@vllnt/convex-email 0.1.0 → 0.1.1-canary.3acc55a
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/CHANGELOG.md +144 -0
- package/README.md +173 -56
- package/dist/client/index.d.ts +9 -4
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +19 -10
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +8 -7
- package/dist/client/types.d.ts.map +1 -1
- package/dist/component/crons.js +1 -1
- package/dist/component/crons.js.map +1 -1
- package/dist/component/mutations.d.ts +12 -7
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +36 -8
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.d.ts +10 -10
- package/dist/component/queries.d.ts.map +1 -1
- package/dist/component/queries.js +9 -7
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.d.ts +4 -4
- package/dist/component/schema.js +1 -1
- package/dist/component/schema.js.map +1 -1
- package/dist/component/validators.d.ts +4 -4
- package/dist/smtp/index.d.ts +5 -3
- package/dist/smtp/index.d.ts.map +1 -1
- package/dist/smtp/index.js +5 -3
- package/dist/smtp/index.js.map +1 -1
- package/dist/smtp/transport.d.ts +2 -2
- package/dist/smtp/transport.js +2 -2
- package/dist/smtp/types.d.ts +5 -5
- package/dist/smtp/types.d.ts.map +1 -1
- package/docs/API.md +441 -0
- package/llms.txt +39 -0
- package/package.json +39 -22
- package/src/client/index.ts +19 -10
- package/src/client/types.ts +8 -7
- package/src/component/crons.ts +1 -1
- package/src/component/mutations.ts +36 -8
- package/src/component/queries.ts +10 -8
- package/src/component/schema.ts +1 -1
- package/src/smtp/index.ts +5 -3
- package/src/smtp/transport.ts +2 -2
- package/src/smtp/types.ts +5 -5
- package/src/test.ts +10 -2
- package/src/jmap/send.test.ts +0 -634
- package/src/smtp/send.test.ts +0 -261
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - Unreleased
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- The npm tarball now ships `docs/API.md`, `CHANGELOG.md` and `llms.txt` next to `README.md`, so
|
|
12
|
+
coding agents can read docs that match the installed version from
|
|
13
|
+
`node_modules/@vllnt/convex-email/`. `README.md` and `llms.txt` gain a "For coding agents" note,
|
|
14
|
+
and the README a "Related packages" section.
|
|
15
|
+
- `docs/API.md` now has an entry-point map and documents the `@vllnt/convex-email/test` helper,
|
|
16
|
+
`JmapDiscoverOptions` and the SMTP and JMAP sender and transport types.
|
|
17
|
+
- `pnpm lint` (run by CI and before every publish) fails when a required file (`README.md`,
|
|
18
|
+
`LICENSE`, `CHANGELOG.md`, `llms.txt`, `docs/API.md`) is missing from the packed tarball, or
|
|
19
|
+
when an inline Markdown link in `llms.txt`, `README.md` or `docs/API.md` points outside the
|
|
20
|
+
tarball or uses a GitHub URL into this repository for a shipped file
|
|
21
|
+
(`scripts/check-package-docs.mjs`).
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Shipped TSDoc: the `Email` and `Parser` docs no longer suggest a `convex/values`
|
|
26
|
+
validator's `.parse` (it has none), and `prune` documents its real default cutoff (30 days
|
|
27
|
+
before the server clock).
|
|
28
|
+
- `enqueue` rejects an empty `messageId`, `to`, `from`, `transport` or `idempotencyKey` with
|
|
29
|
+
`ConvexError({ code: "INVALID_ARGUMENT" })`, and a `maxAttempts` that is not a positive
|
|
30
|
+
integer with `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })`.
|
|
31
|
+
- `@vllnt/convex-email/test` now type-checks under `moduleResolution: nodenext` (explicit `.js`
|
|
32
|
+
relative imports, Vite client types referenced).
|
|
33
|
+
- `register(t)` from `@vllnt/convex-email/test` accepts a host app's
|
|
34
|
+
`convexTest(hostSchema, modules)` instance; it was typed to the component's own schema, so a
|
|
35
|
+
host schema failed with TS2345. Type-only change; CI now type-checks a host-schema test.
|
|
36
|
+
- The docs now state that importing `@vllnt/convex-email/smtp` requires `nodemailer` to be
|
|
37
|
+
installed, even for the pure helpers; `.`, `./jmap` and `./convex.config` never need it. CI
|
|
38
|
+
checks this by importing every runtime entry point from the packed tarball, with and without
|
|
39
|
+
`nodemailer`.
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- `package.json` `homepage` is now `https://oss.vllnt.com/packages/convex-email`. `llms.txt` links
|
|
44
|
+
to shipped files are relative; links to files outside the package are absolute GitHub URLs.
|
|
45
|
+
- The Publish workflow publishes a `canary` on every push to `main` that touches the package or its
|
|
46
|
+
shipped docs, with no repository-variable gate. A canary is published under
|
|
47
|
+
the `canary` dist-tag only and never moves `latest`.
|
|
48
|
+
- Adopt pnpm 10 with a release-age gate; releases are published only from CI with npm
|
|
49
|
+
trusted publishing and provenance.
|
|
50
|
+
- The optional `nodemailer` peer range is now `^8.0.4 || ^9.0.0 || ^10.0.0` (was `^8.0.4`),
|
|
51
|
+
so hosts can move to nodemailer 10.1.4 or later, which fixes the addressparser DoS and
|
|
52
|
+
recipient-domain-bypass advisories still open in 8.x and 9.x. Prefer `^10.1.4`, the first
|
|
53
|
+
release without a published advisory; it requires Node 20+. This package's own tests now
|
|
54
|
+
run on nodemailer 10 and `@types/nodemailer` is dropped (nodemailer 10 ships its types).
|
|
55
|
+
- `MessageView`'s optional fields (`payload`, `subjectRef`, `idempotencyKey`, `providerId`,
|
|
56
|
+
`error`) and `SmtpMailOptions`' optional fields are typed `?: T | undefined`, matching what
|
|
57
|
+
the client returns. Hosts without `exactOptionalPropertyTypes` see no change; a host with
|
|
58
|
+
it enabled that assigns these values to its own `?: T` fields now needs `| undefined` there.
|
|
59
|
+
The client no longer sends optional arguments that are `undefined`; the values on the wire
|
|
60
|
+
are the same.
|
|
61
|
+
- Development dependencies upgraded: `convex` 1.51, `convex-test` 0.0.73, `vitest` 5.1.1,
|
|
62
|
+
`eslint` 10, `@vllnt/typescript` 3 (stricter compiler flags), `nodemailer` 10.6.1, the
|
|
63
|
+
`minimatch` override 11.0.9, pnpm 10.34.9, Node 24.22.3. The `convex` and `nodemailer` peer
|
|
64
|
+
ranges are unchanged.
|
|
65
|
+
|
|
66
|
+
## [0.1.0] - 2026-09-01
|
|
67
|
+
|
|
68
|
+
### Added
|
|
69
|
+
|
|
70
|
+
- First release of `@vllnt/convex-email` — a durable, transport-agnostic outbound
|
|
71
|
+
transactional email queue.
|
|
72
|
+
- Provider-neutral: the transport is a host-configured, host-driven adapter
|
|
73
|
+
(`transport` is an opaque string tag). The component records send intent and
|
|
74
|
+
per-message status and **never calls a mail provider**.
|
|
75
|
+
- `enqueue(messageId, to, from, transport, opts?)` records a message in `queued`
|
|
76
|
+
and returns its id immediately; `messageId` is host-supplied and must be unique.
|
|
77
|
+
An `idempotencyKey` dedups a re-enqueue (`deduplicated: true`) so a retry never
|
|
78
|
+
double-sends.
|
|
79
|
+
- `markSending(messageId)` claims a `queued` message for a send attempt
|
|
80
|
+
(increments `attempts`); `markSent(messageId, { providerId? })` records a
|
|
81
|
+
terminal success; `markFailed(messageId, { error? })` re-queues while
|
|
82
|
+
`attempts < maxAttempts` else lands in terminal `failed`.
|
|
83
|
+
- `get(messageId)` returns the current envelope (or `null`); `listByStatus(status,
|
|
84
|
+
paginationOpts)` pages messages in one status oldest-first via the standard
|
|
85
|
+
Convex pagination envelope.
|
|
86
|
+
- Terminal states are final: any transition out of `sent`/`failed` is rejected
|
|
87
|
+
with `ConvexError({ code: "TERMINAL_STATE" })`, so a late or duplicate delivery
|
|
88
|
+
callback can never overwrite a recorded outcome; `markSent` is idempotent.
|
|
89
|
+
- Server-sourced time: every handler stamps `createdAt`/`updatedAt` from
|
|
90
|
+
`Date.now()` inside the mutation — no caller-supplied clock.
|
|
91
|
+
- Typed generics: `Email<TPayload>` with an optional `payloadValidator` host
|
|
92
|
+
parser narrowing the opaque stored `payload` at the client boundary on write and
|
|
93
|
+
read — no `v.any()` dump, no unchecked cast.
|
|
94
|
+
- Bounded, self-rescheduling `prune` (`take(batch)` + scheduler) that removes only
|
|
95
|
+
terminal messages past their `updatedAt` cutoff, plus a built-in daily prune
|
|
96
|
+
cron (`crons.ts`); idempotent. Default retention 30 days.
|
|
97
|
+
- Mount-safe: correct under multiple `app.use(component, { name })` mounts — each
|
|
98
|
+
instance is sandboxed, the cron is registered per instance.
|
|
99
|
+
- **Optional generic SMTP transport** (`@vllnt/convex-email/smtp`) — sends a queued
|
|
100
|
+
message over **any** SMTP server (Stalwart, Postfix, any provider's relay). The
|
|
101
|
+
server is host config.
|
|
102
|
+
- `sendViaSmtp(transport, message, config?)` — the **pure, injectable** send core
|
|
103
|
+
(driven by an injected `SmtpTransport`), plus `validateSmtpConfig` and
|
|
104
|
+
`toMailOptions`. The validators reject CR/LF (SMTP header) injection in every
|
|
105
|
+
address, subject, and header value.
|
|
106
|
+
- `createSmtpTransport(config)` / `createSmtpSender(config)` — the **thin
|
|
107
|
+
`nodemailer` wrapper**, called from the host's own `"use node"` action.
|
|
108
|
+
- `example/convex/` includes `flushQueuedOverSmtp` — the queue→send wiring
|
|
109
|
+
(`listByStatus("queued")` → `markSending` → send → `markSent`/`markFailed`)
|
|
110
|
+
exercised end to end against the component runtime with a fake transport.
|
|
111
|
+
- `nodemailer` is an **optional peer dependency** (`^8.0.4` — the floor that fixes
|
|
112
|
+
the `envelope.size` CRLF injection advisory GHSA-c7w3-x93f-qmm8 / CVE-2025-14874).
|
|
113
|
+
The queue core still installs and runs with **zero third-party runtime deps**; only
|
|
114
|
+
a host importing `@vllnt/convex-email/smtp` pulls `nodemailer`.
|
|
115
|
+
- **Optional generic JMAP transport** (`@vllnt/convex-email/jmap`) — sends a queued
|
|
116
|
+
message over **any JMAP server's HTTP API** (Stalwart, Fastmail, Cyrus, Apache
|
|
117
|
+
James). JMAP is the protocol (RFC 8620/8621); the server is host config, so no
|
|
118
|
+
vendor is baked in — the adapter is `./jmap`, never `./stalwart`.
|
|
119
|
+
- Runs in a **plain Convex action** — JMAP is HTTP, so `fetch` works in V8: **no
|
|
120
|
+
`"use node"`, no `nodemailer`, zero extra dependencies** (unlike the SMTP
|
|
121
|
+
adapter's raw socket).
|
|
122
|
+
- Pure, injected-`fetch` core — `sendViaJmap(fetchFn, message, config)`,
|
|
123
|
+
`discoverJmapSession(fetchFn, opts)` (resolves account / identity / Sent mailbox
|
|
124
|
+
from the JMAP session), `createJmapSender(config, fetchFn)`, plus
|
|
125
|
+
`validateJmapConfig` / `buildEmailCreate` / `buildSubmitRequest` /
|
|
126
|
+
`parseSubmitResponse`. The whole adapter is **100% covered** with a fake `fetch`
|
|
127
|
+
(no excluded wrapper); it rejects CR/LF header injection in every address,
|
|
128
|
+
subject, and header value.
|
|
129
|
+
- `example/convex/` adds `flushQueuedOverJmap` (the queue→JMAP wiring) and
|
|
130
|
+
`flushQueuedRouted` (one queue routed per message by its `transport` tag —
|
|
131
|
+
`smtp` vs `jmap`), exercised end to end against the component runtime with a
|
|
132
|
+
fake `fetch`.
|
|
133
|
+
|
|
134
|
+
### Fixed
|
|
135
|
+
|
|
136
|
+
- Apply the documented 30-day terminal-message retention and reject invalid prune batches to
|
|
137
|
+
prevent premature audit deletion and scheduler loops.
|
|
138
|
+
|
|
139
|
+
### Changed
|
|
140
|
+
|
|
141
|
+
- Treat Convex `_generated` output as CLI-owned, exclude it from formatting, and expose a
|
|
142
|
+
dedicated codegen script.
|
|
143
|
+
- Refresh all direct dependencies to their latest compatible releases .
|
|
144
|
+
- Require `convex@^1.45.0` and update `convex-test` to `^0.0.56`.
|
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<!-- Badges -->
|
|
2
|
+
|
|
2
3
|
[](https://www.convex.dev/components)
|
|
3
4
|
[](https://www.npmjs.com/package/@vllnt/convex-email)
|
|
4
5
|
[](https://github.com/vllnt/convex-email/actions/workflows/ci.yml)
|
|
@@ -6,36 +7,67 @@
|
|
|
6
7
|
|
|
7
8
|
# @vllnt/convex-email
|
|
8
9
|
|
|
9
|
-
A durable, transport-agnostic outbound transactional email queue, as a Convex
|
|
10
|
+
A durable, transport-agnostic outbound transactional email queue, as a Convex
|
|
11
|
+
component — the host enqueues a message, its own transport sends it, and clients
|
|
12
|
+
poll the delivery status.
|
|
10
13
|
|
|
11
14
|
```ts
|
|
12
15
|
const email = new Email(components.email);
|
|
13
16
|
await email.enqueue(ctx, messageId, to, from, "smtp", { idempotencyKey });
|
|
14
17
|
await email.markSending(ctx, messageId); // host sends, then:
|
|
15
|
-
await email.markSent(ctx, messageId, { providerId }); // or markFailed →
|
|
18
|
+
await email.markSent(ctx, messageId, { providerId }); // or markFailed → host schedules retry
|
|
16
19
|
```
|
|
17
20
|
|
|
18
21
|
## Features
|
|
19
22
|
|
|
20
|
-
- **Enqueue-and-return** — insert a `queued` message, get its id back; the
|
|
21
|
-
|
|
22
|
-
- **
|
|
23
|
-
|
|
24
|
-
- **
|
|
25
|
-
|
|
26
|
-
- **
|
|
27
|
-
|
|
23
|
+
- **Enqueue-and-return** — insert a `queued` message, get its id back; the
|
|
24
|
+
caller never blocks on the send.
|
|
25
|
+
- **Host-driven transport** — the host claims (`markSending`), sends, and
|
|
26
|
+
reports (`markSent`/`markFailed`); the component never reaches a provider.
|
|
27
|
+
- **Optional generic SMTP adapter** — `@vllnt/convex-email/smtp` sends through
|
|
28
|
+
any SMTP server; `nodemailer` is an optional peer dep.
|
|
29
|
+
- **Optional generic JMAP adapter** — `@vllnt/convex-email/jmap` sends over any
|
|
30
|
+
JMAP server's HTTP API (Stalwart, Fastmail, Cyrus) from a plain action —
|
|
31
|
+
`fetch`-based, no `"use node"`, no extra dep.
|
|
32
|
+
- **Idempotent enqueue** — an `idempotencyKey` dedups a re-enqueue while the
|
|
33
|
+
existing row is retained; it does not guarantee exactly-once provider
|
|
34
|
+
delivery.
|
|
35
|
+
- **Retry with budget** — `markFailed` re-queues until `attempts` hit
|
|
36
|
+
`maxAttempts`, then lands in terminal `failed`.
|
|
37
|
+
- **Terminal states are final** — a late or duplicate delivery callback can
|
|
38
|
+
never overwrite a recorded outcome.
|
|
39
|
+
- **Poll or subscribe** — `get` / `listByStatus` update live in a reactive
|
|
40
|
+
Convex query.
|
|
28
41
|
- **Server-sourced time, typed opaque payload, bounded prune cron, mount-safe.**
|
|
29
42
|
|
|
30
43
|
## Installation
|
|
31
44
|
|
|
32
45
|
```bash
|
|
33
|
-
pnpm add @vllnt/convex-email
|
|
46
|
+
pnpm add @vllnt/convex-email convex@^1.45.0
|
|
34
47
|
```
|
|
35
48
|
|
|
36
|
-
|
|
49
|
+
The command installs the latest stable release; use `@vllnt/convex-email@canary`
|
|
50
|
+
for the newest pre-release build from `main`. Peer dependency: `convex@^1.45.0`.
|
|
51
|
+
The queue core has zero third-party runtime deps. `nodemailer`
|
|
52
|
+
(`^8.0.4 || ^9.0.0 || ^10.0.0`) is an optional peer dep — only for the SMTP
|
|
53
|
+
transport. The JMAP transport (`@vllnt/convex-email/jmap`) is `fetch`-based and
|
|
54
|
+
needs no extra dependency.
|
|
55
|
+
|
|
56
|
+
This README ships inside the package and describes the installed version; the
|
|
57
|
+
copy on GitHub `main` can be ahead of `latest`. Pin an exact canary version for
|
|
58
|
+
reproducible installs.
|
|
59
|
+
|
|
60
|
+
## For coding agents
|
|
61
|
+
|
|
62
|
+
The docs are bundled at `node_modules/@vllnt/convex-email/docs/`, next to
|
|
63
|
+
`README.md`, `CHANGELOG.md` and `llms.txt`. They match the installed version.
|
|
64
|
+
Read them before writing code against this package.
|
|
37
65
|
|
|
38
|
-
##
|
|
66
|
+
## Quick start
|
|
67
|
+
|
|
68
|
+
After mounting, run `pnpm exec convex dev` to generate `components.email`. This
|
|
69
|
+
internal enqueue function is for trusted server callers; public wrappers must
|
|
70
|
+
check sender/recipient permissions and prevent arbitrary outbound mail.
|
|
39
71
|
|
|
40
72
|
```ts
|
|
41
73
|
// convex/convex.config.ts
|
|
@@ -50,63 +82,98 @@ export default app;
|
|
|
50
82
|
```ts
|
|
51
83
|
// convex/notify.ts — host owns auth AND the transport; pass opaque refs in.
|
|
52
84
|
import { components } from "./_generated/api";
|
|
53
|
-
import {
|
|
85
|
+
import { internalMutation } from "./_generated/server";
|
|
54
86
|
import { v } from "convex/values";
|
|
55
87
|
import { Email } from "@vllnt/convex-email";
|
|
56
88
|
|
|
57
89
|
const email = new Email<{ subject: string; html: string }>(components.email, {
|
|
58
|
-
payloadValidator:
|
|
90
|
+
payloadValidator: (value) => {
|
|
91
|
+
if (
|
|
92
|
+
typeof value !== "object" ||
|
|
93
|
+
value === null ||
|
|
94
|
+
!("subject" in value) ||
|
|
95
|
+
!("html" in value) ||
|
|
96
|
+
typeof value.subject !== "string" ||
|
|
97
|
+
typeof value.html !== "string"
|
|
98
|
+
) {
|
|
99
|
+
throw new Error("Expected subject and html strings");
|
|
100
|
+
}
|
|
101
|
+
return { subject: value.subject, html: value.html };
|
|
102
|
+
},
|
|
59
103
|
});
|
|
60
104
|
|
|
61
|
-
//
|
|
62
|
-
export const sendWelcome =
|
|
105
|
+
// Record intent only. A host worker polls queued messages and sends them.
|
|
106
|
+
export const sendWelcome = internalMutation({
|
|
63
107
|
args: { userId: v.string(), to: v.string() },
|
|
64
108
|
handler: async (ctx, { userId, to }) => {
|
|
65
109
|
const messageId = crypto.randomUUID();
|
|
66
|
-
|
|
110
|
+
return email.enqueue(ctx, messageId, to, "no-reply@example.com", "jmap", {
|
|
67
111
|
payload: { subject: "Welcome", html: "<p>Hello</p>" },
|
|
68
|
-
idempotencyKey: `welcome:${userId}`, //
|
|
112
|
+
idempotencyKey: `welcome:${userId}`, // returns the existing id when deduplicated
|
|
69
113
|
});
|
|
70
|
-
await ctx.scheduler.runAfter(0, internal.notify.flush, { messageId });
|
|
71
|
-
return { messageId };
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// 2) The host's transport sender claims, dispatches, and reports the outcome.
|
|
76
|
-
export const flush = internalAction({
|
|
77
|
-
args: { messageId: v.string() },
|
|
78
|
-
handler: async (ctx, { messageId }) => {
|
|
79
|
-
await email.markSending(ctx, messageId);
|
|
80
|
-
try {
|
|
81
|
-
const providerId = await sendOverJmap(messageId); // your transport
|
|
82
|
-
await email.markSent(ctx, messageId, { providerId });
|
|
83
|
-
} catch (e) {
|
|
84
|
-
const { retried } = await email.markFailed(ctx, messageId, { error: String(e) });
|
|
85
|
-
if (retried) await ctx.scheduler.runAfter(backoffMs(), internal.notify.flush, { messageId });
|
|
86
|
-
}
|
|
87
114
|
},
|
|
88
115
|
});
|
|
89
116
|
```
|
|
90
117
|
|
|
91
118
|
## API Reference
|
|
92
119
|
|
|
93
|
-
| Method
|
|
94
|
-
|
|
95
|
-
| `enqueue(ctx, messageId, to, from, transport, opts?)` | mutation | `{ messageId, deduplicated }`
|
|
96
|
-
| `markSending(ctx, messageId)`
|
|
97
|
-
| `markSent(ctx, messageId, opts?)`
|
|
98
|
-
| `markFailed(ctx, messageId, opts?)`
|
|
99
|
-
| `get(ctx, messageId)`
|
|
100
|
-
| `listByStatus(ctx, status, paginationOpts)`
|
|
101
|
-
| `prune(ctx, opts?)`
|
|
120
|
+
| Method | Kind | Result |
|
|
121
|
+
| ----------------------------------------------------- | -------- | ------------------------------- |
|
|
122
|
+
| `enqueue(ctx, messageId, to, from, transport, opts?)` | mutation | `{ messageId, deduplicated }` |
|
|
123
|
+
| `markSending(ctx, messageId)` | mutation | `{ attempts }` |
|
|
124
|
+
| `markSent(ctx, messageId, opts?)` | mutation | `null` |
|
|
125
|
+
| `markFailed(ctx, messageId, opts?)` | mutation | `{ status, retried }` |
|
|
126
|
+
| `get(ctx, messageId)` | query | `MessageView \| null` |
|
|
127
|
+
| `listByStatus(ctx, status, paginationOpts)` | query | `PaginationResult<MessageView>` |
|
|
128
|
+
| `prune(ctx, opts?)` | mutation | `number` |
|
|
102
129
|
|
|
103
130
|
Full reference: [docs/API.md](docs/API.md).
|
|
104
131
|
|
|
132
|
+
## Options and limitations
|
|
133
|
+
|
|
134
|
+
- Constructor: `payloadValidator?: (unknown) => TPayload` and
|
|
135
|
+
`maxAttempts?: number` (default 5, positive integer). Convex `v.*` validators
|
|
136
|
+
do not have `.parse`.
|
|
137
|
+
- Enqueue options: `{ payload?, subjectRef?, idempotencyKey?, maxAttempts? }`.
|
|
138
|
+
Use the returned `messageId`, which may differ from the proposed id on
|
|
139
|
+
deduplication.
|
|
140
|
+
- The host polls `listByStatus("queued")`, claims with `markSending`, calls a
|
|
141
|
+
transport, and reports the outcome. `markFailed` only requeues; it does not
|
|
142
|
+
send, schedule backoff, or recover a crashed worker stuck in `sending`.
|
|
143
|
+
- No exactly-once transport guarantee: a provider may accept a message before a
|
|
144
|
+
network error or status-write failure. Do not treat a failed `markSent` as
|
|
145
|
+
proof the send failed; reconcile ambiguous outcomes before retrying.
|
|
146
|
+
- `markSent` and `markFailed` also accept `queued` rows; the host must maintain
|
|
147
|
+
claim/send/report discipline. Only `markSending` increments attempts.
|
|
148
|
+
- Prune defaults to 30 days from terminal `updatedAt`, batch 200 (integer
|
|
149
|
+
1–500). Custom cutoffs do not extend the built-in daily cron's retention;
|
|
150
|
+
pruning removes the row's dedup key too.
|
|
151
|
+
- Mount separately with `app.use(email, { name: "transactionalEmail" })` and
|
|
152
|
+
`new Email(components.transactionalEmail)`.
|
|
153
|
+
|
|
154
|
+
## Integrations
|
|
155
|
+
|
|
156
|
+
No `./react` entry: expose authorized host queries for delivery status. Provider
|
|
157
|
+
credentials stay in host actions, never in message payloads or client bundles.
|
|
158
|
+
|
|
105
159
|
## SMTP transport (optional)
|
|
106
160
|
|
|
107
|
-
A generic SMTP adapter ships at `@vllnt/convex-email/smtp` — it sends through
|
|
161
|
+
A generic SMTP adapter ships at `@vllnt/convex-email/smtp` — it sends through
|
|
162
|
+
any SMTP server (Stalwart, Postfix, any relay). The real send runs in the host's
|
|
163
|
+
own `"use node"` action; the component never sends.
|
|
164
|
+
|
|
165
|
+
Install the optional peer with `pnpm add nodemailer@^10.1.4`. The accepted range
|
|
166
|
+
is `^8.0.4 || ^9.0.0 || ^10.0.0`, but 10.1.4 is the first release without a
|
|
167
|
+
published advisory (8.x and 9.x still carry addressparser DoS and
|
|
168
|
+
recipient-domain bypass advisories). nodemailer 10 needs Node 20+.
|
|
169
|
+
|
|
170
|
+
Importing `@vllnt/convex-email/smtp` requires `nodemailer` to be installed, even
|
|
171
|
+
for the pure helpers (`sendViaSmtp`, `validateSmtpConfig`, `toMailOptions`);
|
|
172
|
+
without it the import fails with `ERR_MODULE_NOT_FOUND`. `@vllnt/convex-email`
|
|
173
|
+
and `@vllnt/convex-email/jmap` never need it.
|
|
108
174
|
|
|
109
175
|
```ts
|
|
176
|
+
"use node";
|
|
110
177
|
import { createSmtpSender } from "@vllnt/convex-email/smtp";
|
|
111
178
|
|
|
112
179
|
const send = createSmtpSender({
|
|
@@ -121,10 +188,16 @@ Full queue-to-SMTP wiring in [docs/API.md](docs/API.md).
|
|
|
121
188
|
|
|
122
189
|
## JMAP transport (optional)
|
|
123
190
|
|
|
124
|
-
A generic JMAP adapter ships at `@vllnt/convex-email/jmap` — it sends over any
|
|
191
|
+
A generic JMAP adapter ships at `@vllnt/convex-email/jmap` — it sends over any
|
|
192
|
+
JMAP server's HTTP API (Stalwart, Fastmail, Cyrus, Apache James). JMAP is HTTP,
|
|
193
|
+
so it runs in a **plain Convex action** — no `"use node"`, no `nodemailer`, zero
|
|
194
|
+
extra deps. It's a protocol, not a vendor: `./jmap`, never `./stalwart`.
|
|
125
195
|
|
|
126
196
|
```ts
|
|
127
|
-
import {
|
|
197
|
+
import {
|
|
198
|
+
createJmapSender,
|
|
199
|
+
discoverJmapSession,
|
|
200
|
+
} from "@vllnt/convex-email/jmap";
|
|
128
201
|
|
|
129
202
|
// Resolve account / identity / Sent mailbox once, then bind a sender over your `fetch`.
|
|
130
203
|
const config = await discoverJmapSession((u, i) => fetch(u, i), {
|
|
@@ -135,12 +208,17 @@ const config = await discoverJmapSession((u, i) => fetch(u, i), {
|
|
|
135
208
|
const send = createJmapSender(config, (u, i) => fetch(u, i));
|
|
136
209
|
```
|
|
137
210
|
|
|
138
|
-
To send some mail over SMTP and some over Stalwart's HTTP (JMAP), keep **one
|
|
211
|
+
To send some mail over SMTP and some over Stalwart's HTTP (JMAP), keep **one
|
|
212
|
+
queue** and route per message by its stored `transport` tag (a `senders` map
|
|
213
|
+
keyed by `"smtp"` / `"jmap"`). Full JMAP wiring + routing in
|
|
214
|
+
[docs/API.md](docs/API.md).
|
|
139
215
|
|
|
140
216
|
## Security
|
|
141
217
|
|
|
142
|
-
- Auth-agnostic and provider-neutral — the host gates access and drives the
|
|
143
|
-
|
|
218
|
+
- Auth-agnostic and provider-neutral — the host gates access and drives the
|
|
219
|
+
transport; the component never authenticates or contacts a provider.
|
|
220
|
+
- Tables are sandboxed (reached only via exported functions); the stored
|
|
221
|
+
`payload` is opaque.
|
|
144
222
|
- Terminal states are final, enqueue is idempotent, and time is server-sourced.
|
|
145
223
|
|
|
146
224
|
See [docs/API.md](docs/API.md).
|
|
@@ -152,20 +230,59 @@ pnpm test # single run
|
|
|
152
230
|
pnpm test:coverage # enforced 100% on covered files
|
|
153
231
|
```
|
|
154
232
|
|
|
155
|
-
Tests run against the real component runtime via `convex-test`
|
|
233
|
+
Tests run against the real component runtime via `convex-test`
|
|
234
|
+
(`@edge-runtime/vm`), not mocks.
|
|
235
|
+
|
|
236
|
+
### Testing your app
|
|
237
|
+
|
|
238
|
+
`@vllnt/convex-email/test` exports `register(t, name = "email")` to mount the
|
|
239
|
+
component in a `convex-test` instance. It needs `convex-test` and `vitest` (with
|
|
240
|
+
Vite's `import.meta.glob`) in the consuming app:
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
/// <reference types="vite/client" />
|
|
244
|
+
import { convexTest } from "convex-test";
|
|
245
|
+
import { register } from "@vllnt/convex-email/test";
|
|
246
|
+
import schema from "./schema";
|
|
247
|
+
|
|
248
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
249
|
+
register(t);
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Documentation
|
|
253
|
+
|
|
254
|
+
`llms.txt` is the maintained discovery index. `pnpm generate:llms` checks its
|
|
255
|
+
heading and local links without generating a source bundle.
|
|
256
|
+
|
|
257
|
+
[API reference](docs/API.md) · [LLM index](llms.txt) ·
|
|
258
|
+
[Security policy](https://github.com/vllnt/convex-email/blob/main/SECURITY.md)
|
|
259
|
+
|
|
260
|
+
## Related packages
|
|
261
|
+
|
|
262
|
+
Separate `@vllnt` Convex components; this one never calls them. The host wires
|
|
263
|
+
any of them in its own code.
|
|
264
|
+
|
|
265
|
+
| Package | Use it when |
|
|
266
|
+
| ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
|
|
267
|
+
| [`@vllnt/convex-suppression`](https://github.com/vllnt/convex-suppression) | You keep a do-not-contact list. Check it before enqueueing so a suppressed address is never queued. |
|
|
268
|
+
| [`@vllnt/convex-consent`](https://github.com/vllnt/convex-consent) | You must record, withdraw and gate consent per subject and purpose before sending permission-based mail. |
|
|
269
|
+
| [`@vllnt/convex-notifications`](https://github.com/vllnt/convex-notifications) | The message is an in-app inbox item with read/unread state, not an email. |
|
|
270
|
+
| [`@vllnt/convex-idempotency`](https://github.com/vllnt/convex-idempotency) | You need an idempotency-key ledger for other retried operations. This package's `idempotencyKey` only dedups `enqueue`. |
|
|
156
271
|
|
|
157
272
|
## Contributing
|
|
158
273
|
|
|
159
|
-
See
|
|
274
|
+
See
|
|
275
|
+
[CONTRIBUTING.md](https://github.com/vllnt/convex-email/blob/main/CONTRIBUTING.md).
|
|
160
276
|
|
|
161
277
|
## Author
|
|
162
278
|
|
|
163
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
164
|
-
|
|
165
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet — [vllnt.com](https://vllnt.com)
|
|
279
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
280
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
166
281
|
|
|
167
282
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
168
283
|
|
|
169
284
|
## License
|
|
170
285
|
|
|
171
286
|
MIT — see [LICENSE](LICENSE).
|
|
287
|
+
|
|
288
|
+
Part of vllnt oss: https://oss.vllnt.com
|
package/dist/client/index.d.ts
CHANGED
|
@@ -94,11 +94,16 @@ interface RunMutationCtx {
|
|
|
94
94
|
*
|
|
95
95
|
* @example
|
|
96
96
|
* ```ts
|
|
97
|
-
* const email = new Email(components.email, {
|
|
98
|
-
* payloadValidator:
|
|
97
|
+
* const email = new Email<{ subject: string }>(components.email, {
|
|
98
|
+
* payloadValidator: (value) => {
|
|
99
|
+
* if (typeof value !== "object" || value === null || !("subject" in value) || typeof value.subject !== "string") {
|
|
100
|
+
* throw new Error("Expected { subject: string }");
|
|
101
|
+
* }
|
|
102
|
+
* return { subject: value.subject };
|
|
103
|
+
* },
|
|
99
104
|
* });
|
|
100
105
|
* const { messageId } = await email.enqueue(ctx, id, "user@x.com", "no-reply@app.com", "jmap", {
|
|
101
|
-
* payload: { subject: "Hi"
|
|
106
|
+
* payload: { subject: "Hi" },
|
|
102
107
|
* idempotencyKey: `welcome:${userId}`,
|
|
103
108
|
* });
|
|
104
109
|
* // ... the host's transport sender:
|
|
@@ -161,7 +166,7 @@ export declare class Email<TPayload = unknown> {
|
|
|
161
166
|
listByStatus(ctx: RunQueryCtx, status: MessageStatus, paginationOpts: PaginationOptions): Promise<PaginationResult<MessageView<TPayload>>>;
|
|
162
167
|
/**
|
|
163
168
|
* Delete terminal messages whose `updatedAt < before` in bounded batches,
|
|
164
|
-
* oldest first. `before` defaults to the server clock; `batch` caps each pass
|
|
169
|
+
* oldest first. `before` defaults to 30 days before the server clock; `batch` caps each pass
|
|
165
170
|
* and the sweep self-reschedules until the tail is clean. Returns the count
|
|
166
171
|
* removed in the first pass. The built-in daily cron drives this automatically.
|
|
167
172
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,MAAM,EACP,MAAM,YAAY,CAAC;AAGpB;;;;GAIG;AACH,KAAK,OAAO,GAAG;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE;QACT,OAAO,EAAE,iBAAiB,CACxB,UAAU,EACV,UAAU,EACV;YACE,SAAS,EAAE,MAAM,CAAC;YAClB,EAAE,EAAE,MAAM,CAAC;YACX,IAAI,EAAE,MAAM,CAAC;YACb,SAAS,EAAE,MAAM,CAAC;YAClB,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NE_BATCH } from "../shared.js";
|
|
|
15
15
|
*
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
|
-
* const email = new Email(components.email, {
|
|
19
|
-
* payloadValidator:
|
|
18
|
+
* const email = new Email<{ subject: string }>(components.email, {
|
|
19
|
+
* payloadValidator: (value) => {
|
|
20
|
+
* if (typeof value !== "object" || value === null || !("subject" in value) || typeof value.subject !== "string") {
|
|
21
|
+
* throw new Error("Expected { subject: string }");
|
|
22
|
+
* }
|
|
23
|
+
* return { subject: value.subject };
|
|
24
|
+
* },
|
|
20
25
|
* });
|
|
21
26
|
* const { messageId } = await email.enqueue(ctx, id, "user@x.com", "no-reply@app.com", "jmap", {
|
|
22
|
-
* payload: { subject: "Hi"
|
|
27
|
+
* payload: { subject: "Hi" },
|
|
23
28
|
* idempotencyKey: `welcome:${userId}`,
|
|
24
29
|
* });
|
|
25
30
|
* // ... the host's transport sender:
|
|
@@ -82,9 +87,13 @@ export class Email {
|
|
|
82
87
|
to,
|
|
83
88
|
from,
|
|
84
89
|
transport,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
...(opts.payload === undefined
|
|
91
|
+
? {}
|
|
92
|
+
: { payload: this.parse(opts.payload) }),
|
|
93
|
+
...(opts.subjectRef === undefined ? {} : { subjectRef: opts.subjectRef }),
|
|
94
|
+
...(opts.idempotencyKey === undefined
|
|
95
|
+
? {}
|
|
96
|
+
: { idempotencyKey: opts.idempotencyKey }),
|
|
88
97
|
maxAttempts: opts.maxAttempts ?? this.maxAttempts,
|
|
89
98
|
});
|
|
90
99
|
}
|
|
@@ -104,7 +113,7 @@ export class Email {
|
|
|
104
113
|
markSent(ctx, messageId, opts = {}) {
|
|
105
114
|
return ctx.runMutation(this.component.mutations.markSent, {
|
|
106
115
|
messageId,
|
|
107
|
-
providerId: opts.providerId,
|
|
116
|
+
...(opts.providerId === undefined ? {} : { providerId: opts.providerId }),
|
|
108
117
|
});
|
|
109
118
|
}
|
|
110
119
|
/**
|
|
@@ -116,7 +125,7 @@ export class Email {
|
|
|
116
125
|
markFailed(ctx, messageId, opts = {}) {
|
|
117
126
|
return ctx.runMutation(this.component.mutations.markFailed, {
|
|
118
127
|
messageId,
|
|
119
|
-
error: opts.error,
|
|
128
|
+
...(opts.error === undefined ? {} : { error: opts.error }),
|
|
120
129
|
});
|
|
121
130
|
}
|
|
122
131
|
/** The current envelope for `messageId`, or `null` if no such message is held. */
|
|
@@ -137,13 +146,13 @@ export class Email {
|
|
|
137
146
|
}
|
|
138
147
|
/**
|
|
139
148
|
* Delete terminal messages whose `updatedAt < before` in bounded batches,
|
|
140
|
-
* oldest first. `before` defaults to the server clock; `batch` caps each pass
|
|
149
|
+
* oldest first. `before` defaults to 30 days before the server clock; `batch` caps each pass
|
|
141
150
|
* and the sweep self-reschedules until the tail is clean. Returns the count
|
|
142
151
|
* removed in the first pass. The built-in daily cron drives this automatically.
|
|
143
152
|
*/
|
|
144
153
|
prune(ctx, opts = {}) {
|
|
145
154
|
return ctx.runMutation(this.component.mutations.prune, {
|
|
146
|
-
before: opts.before,
|
|
155
|
+
...(opts.before === undefined ? {} : { before: opts.before }),
|
|
147
156
|
batch: opts.batch ?? DEFAULT_PRUNE_BATCH,
|
|
148
157
|
});
|
|
149
158
|
}
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAqGzE
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAqGzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,OAAO,KAAK;IAKG,SAAS;IAJX,gBAAgB,CAA+B;I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CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;YAC7D,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,mBAAmB;SACzC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/dist/client/types.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ export type MessageStatus = "queued" | "sending" | "sent" | "failed";
|
|
|
4
4
|
/**
|
|
5
5
|
* Validates and narrows the opaque stored `payload` to a host type `T` at the
|
|
6
6
|
* client boundary. Receives the raw value the component returned (`unknown`) and
|
|
7
|
-
* MUST return a typed `T` or throw. A
|
|
8
|
-
*
|
|
7
|
+
* MUST return a typed `T` or throw. A Zod schema's `.parse` fits directly; a
|
|
8
|
+
* `convex/values` validator has no `.parse`, so write a type guard instead. Omit
|
|
9
|
+
* it to keep the value unvalidated.
|
|
9
10
|
*
|
|
10
11
|
* @typeParam T - The host's stored message `payload` type.
|
|
11
12
|
*/
|
|
@@ -23,19 +24,19 @@ export interface MessageView<TPayload = unknown> {
|
|
|
23
24
|
/** The current lifecycle status. */
|
|
24
25
|
status: MessageStatus;
|
|
25
26
|
/** The opaque rendered message payload (narrowed if a `payloadValidator` is set). */
|
|
26
|
-
payload?: TPayload;
|
|
27
|
+
payload?: TPayload | undefined;
|
|
27
28
|
/** An opaque host ref for subject-centric listing (e.g. the addressee subject). */
|
|
28
|
-
subjectRef?: string;
|
|
29
|
+
subjectRef?: string | undefined;
|
|
29
30
|
/** The dedup key, if the message was enqueued with one. */
|
|
30
|
-
idempotencyKey?: string;
|
|
31
|
+
idempotencyKey?: string | undefined;
|
|
31
32
|
/** The transport's own message handle, recorded once `sent`. */
|
|
32
|
-
providerId?: string;
|
|
33
|
+
providerId?: string | undefined;
|
|
33
34
|
/** The number of send attempts made so far. */
|
|
34
35
|
attempts: number;
|
|
35
36
|
/** The maximum send attempts before a failure is terminal. */
|
|
36
37
|
maxAttempts: number;
|
|
37
38
|
/** The host-supplied failure reason from the last failed attempt. */
|
|
38
|
-
error?: string;
|
|
39
|
+
error?: string | undefined;
|
|
39
40
|
/** Absolute ms timestamp the message was enqueued. */
|
|
40
41
|
createdAt: number;
|
|
41
42
|
/** Absolute ms timestamp of the last transition. */
|