@vllnt/convex-email 0.1.0 → 0.1.1-canary.d88db7c
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 +142 -54
- package/dist/component/crons.js +1 -1
- package/dist/component/crons.js.map +1 -1
- package/dist/component/mutations.d.ts +5 -0
- package/dist/component/mutations.d.ts.map +1 -1
- package/dist/component/mutations.js +30 -4
- package/dist/component/mutations.js.map +1 -1
- package/dist/component/queries.js +2 -2
- package/dist/component/queries.js.map +1 -1
- package/dist/component/schema.js +1 -1
- package/dist/component/schema.js.map +1 -1
- package/package.json +23 -13
- package/src/component/crons.ts +1 -1
- package/src/component/mutations.ts +30 -4
- package/src/component/queries.ts +3 -3
- package/src/component/schema.ts +1 -1
- package/src/test.ts +2 -1
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,58 @@
|
|
|
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@canary convex@^1.45.0
|
|
34
47
|
```
|
|
35
48
|
|
|
36
|
-
Peer dependency: `convex@^1.
|
|
49
|
+
Peer dependency: `convex@^1.45.0`. The queue core has zero third-party runtime
|
|
50
|
+
deps. `nodemailer@^8.0.4` is an optional peer dep — only for the SMTP transport.
|
|
51
|
+
The JMAP transport (`@vllnt/convex-email/jmap`) is `fetch`-based and needs no
|
|
52
|
+
extra dependency.
|
|
53
|
+
|
|
54
|
+
This README follows `main` and the canary channel; `latest` is the separate
|
|
55
|
+
stable release. Pin an exact canary version for reproducible installs.
|
|
56
|
+
|
|
57
|
+
## Quick start
|
|
37
58
|
|
|
38
|
-
|
|
59
|
+
After mounting, run `pnpm exec convex dev` to generate `components.email`. This
|
|
60
|
+
internal enqueue function is for trusted server callers; public wrappers must
|
|
61
|
+
check sender/recipient permissions and prevent arbitrary outbound mail.
|
|
39
62
|
|
|
40
63
|
```ts
|
|
41
64
|
// convex/convex.config.ts
|
|
@@ -50,63 +73,90 @@ export default app;
|
|
|
50
73
|
```ts
|
|
51
74
|
// convex/notify.ts — host owns auth AND the transport; pass opaque refs in.
|
|
52
75
|
import { components } from "./_generated/api";
|
|
53
|
-
import {
|
|
76
|
+
import { internalMutation } from "./_generated/server";
|
|
54
77
|
import { v } from "convex/values";
|
|
55
78
|
import { Email } from "@vllnt/convex-email";
|
|
56
79
|
|
|
57
80
|
const email = new Email<{ subject: string; html: string }>(components.email, {
|
|
58
|
-
payloadValidator:
|
|
81
|
+
payloadValidator: (value) => {
|
|
82
|
+
if (
|
|
83
|
+
typeof value !== "object" ||
|
|
84
|
+
value === null ||
|
|
85
|
+
!("subject" in value) ||
|
|
86
|
+
!("html" in value) ||
|
|
87
|
+
typeof value.subject !== "string" ||
|
|
88
|
+
typeof value.html !== "string"
|
|
89
|
+
) {
|
|
90
|
+
throw new Error("Expected subject and html strings");
|
|
91
|
+
}
|
|
92
|
+
return { subject: value.subject, html: value.html };
|
|
93
|
+
},
|
|
59
94
|
});
|
|
60
95
|
|
|
61
|
-
//
|
|
62
|
-
export const sendWelcome =
|
|
96
|
+
// Record intent only. A host worker polls queued messages and sends them.
|
|
97
|
+
export const sendWelcome = internalMutation({
|
|
63
98
|
args: { userId: v.string(), to: v.string() },
|
|
64
99
|
handler: async (ctx, { userId, to }) => {
|
|
65
100
|
const messageId = crypto.randomUUID();
|
|
66
|
-
|
|
101
|
+
return email.enqueue(ctx, messageId, to, "no-reply@example.com", "jmap", {
|
|
67
102
|
payload: { subject: "Welcome", html: "<p>Hello</p>" },
|
|
68
|
-
idempotencyKey: `welcome:${userId}`, //
|
|
103
|
+
idempotencyKey: `welcome:${userId}`, // returns the existing id when deduplicated
|
|
69
104
|
});
|
|
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
105
|
},
|
|
88
106
|
});
|
|
89
107
|
```
|
|
90
108
|
|
|
91
109
|
## API Reference
|
|
92
110
|
|
|
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?)`
|
|
111
|
+
| Method | Kind | Result |
|
|
112
|
+
| ----------------------------------------------------- | -------- | ------------------------------- |
|
|
113
|
+
| `enqueue(ctx, messageId, to, from, transport, opts?)` | mutation | `{ messageId, deduplicated }` |
|
|
114
|
+
| `markSending(ctx, messageId)` | mutation | `{ attempts }` |
|
|
115
|
+
| `markSent(ctx, messageId, opts?)` | mutation | `null` |
|
|
116
|
+
| `markFailed(ctx, messageId, opts?)` | mutation | `{ status, retried }` |
|
|
117
|
+
| `get(ctx, messageId)` | query | `MessageView \| null` |
|
|
118
|
+
| `listByStatus(ctx, status, paginationOpts)` | query | `PaginationResult<MessageView>` |
|
|
119
|
+
| `prune(ctx, opts?)` | mutation | `number` |
|
|
102
120
|
|
|
103
121
|
Full reference: [docs/API.md](docs/API.md).
|
|
104
122
|
|
|
123
|
+
## Options and limitations
|
|
124
|
+
|
|
125
|
+
- Constructor: `payloadValidator?: (unknown) => TPayload` and
|
|
126
|
+
`maxAttempts?: number` (default 5, positive integer). Convex `v.*` validators do not have
|
|
127
|
+
`.parse`.
|
|
128
|
+
- Enqueue options: `{ payload?, subjectRef?, idempotencyKey?, maxAttempts? }`.
|
|
129
|
+
Use the returned `messageId`, which may differ from the proposed id on
|
|
130
|
+
deduplication.
|
|
131
|
+
- The host polls `listByStatus("queued")`, claims with `markSending`, calls a
|
|
132
|
+
transport, and reports the outcome. `markFailed` only requeues; it does not
|
|
133
|
+
send, schedule backoff, or recover a crashed worker stuck in `sending`.
|
|
134
|
+
- No exactly-once transport guarantee: a provider may accept a message before a
|
|
135
|
+
network error or status-write failure. Do not treat a failed `markSent` as
|
|
136
|
+
proof the send failed; reconcile ambiguous outcomes before retrying.
|
|
137
|
+
- `markSent` and `markFailed` also accept `queued` rows; the host must maintain
|
|
138
|
+
claim/send/report discipline. Only `markSending` increments attempts.
|
|
139
|
+
- Prune defaults to 30 days from terminal `updatedAt`, batch 200 (integer
|
|
140
|
+
1–500). Custom cutoffs do not extend the built-in daily cron's retention;
|
|
141
|
+
pruning removes the row's dedup key too.
|
|
142
|
+
- Mount separately with `app.use(email, { name: "transactionalEmail" })` and
|
|
143
|
+
`new Email(components.transactionalEmail)`.
|
|
144
|
+
|
|
145
|
+
## Integrations
|
|
146
|
+
|
|
147
|
+
No `./react` entry: expose authorized host queries for delivery status. Provider
|
|
148
|
+
credentials stay in host actions, never in message payloads or client bundles.
|
|
149
|
+
|
|
105
150
|
## SMTP transport (optional)
|
|
106
151
|
|
|
107
|
-
A generic SMTP adapter ships at `@vllnt/convex-email/smtp` — it sends through
|
|
152
|
+
A generic SMTP adapter ships at `@vllnt/convex-email/smtp` — it sends through
|
|
153
|
+
any SMTP server (Stalwart, Postfix, any relay). The real send runs in the host's
|
|
154
|
+
own `"use node"` action; the component never sends.
|
|
155
|
+
|
|
156
|
+
Install the optional peer with `pnpm add nodemailer@^8.0.4`.
|
|
108
157
|
|
|
109
158
|
```ts
|
|
159
|
+
"use node";
|
|
110
160
|
import { createSmtpSender } from "@vllnt/convex-email/smtp";
|
|
111
161
|
|
|
112
162
|
const send = createSmtpSender({
|
|
@@ -121,10 +171,16 @@ Full queue-to-SMTP wiring in [docs/API.md](docs/API.md).
|
|
|
121
171
|
|
|
122
172
|
## JMAP transport (optional)
|
|
123
173
|
|
|
124
|
-
A generic JMAP adapter ships at `@vllnt/convex-email/jmap` — it sends over any
|
|
174
|
+
A generic JMAP adapter ships at `@vllnt/convex-email/jmap` — it sends over any
|
|
175
|
+
JMAP server's HTTP API (Stalwart, Fastmail, Cyrus, Apache James). JMAP is HTTP,
|
|
176
|
+
so it runs in a **plain Convex action** — no `"use node"`, no `nodemailer`, zero
|
|
177
|
+
extra deps. It's a protocol, not a vendor: `./jmap`, never `./stalwart`.
|
|
125
178
|
|
|
126
179
|
```ts
|
|
127
|
-
import {
|
|
180
|
+
import {
|
|
181
|
+
createJmapSender,
|
|
182
|
+
discoverJmapSession,
|
|
183
|
+
} from "@vllnt/convex-email/jmap";
|
|
128
184
|
|
|
129
185
|
// Resolve account / identity / Sent mailbox once, then bind a sender over your `fetch`.
|
|
130
186
|
const config = await discoverJmapSession((u, i) => fetch(u, i), {
|
|
@@ -135,12 +191,17 @@ const config = await discoverJmapSession((u, i) => fetch(u, i), {
|
|
|
135
191
|
const send = createJmapSender(config, (u, i) => fetch(u, i));
|
|
136
192
|
```
|
|
137
193
|
|
|
138
|
-
To send some mail over SMTP and some over Stalwart's HTTP (JMAP), keep **one
|
|
194
|
+
To send some mail over SMTP and some over Stalwart's HTTP (JMAP), keep **one
|
|
195
|
+
queue** and route per message by its stored `transport` tag (a `senders` map
|
|
196
|
+
keyed by `"smtp"` / `"jmap"`). Full JMAP wiring + routing in
|
|
197
|
+
[docs/API.md](docs/API.md).
|
|
139
198
|
|
|
140
199
|
## Security
|
|
141
200
|
|
|
142
|
-
- Auth-agnostic and provider-neutral — the host gates access and drives the
|
|
143
|
-
|
|
201
|
+
- Auth-agnostic and provider-neutral — the host gates access and drives the
|
|
202
|
+
transport; the component never authenticates or contacts a provider.
|
|
203
|
+
- Tables are sandboxed (reached only via exported functions); the stored
|
|
204
|
+
`payload` is opaque.
|
|
144
205
|
- Terminal states are final, enqueue is idempotent, and time is server-sourced.
|
|
145
206
|
|
|
146
207
|
See [docs/API.md](docs/API.md).
|
|
@@ -152,7 +213,32 @@ pnpm test # single run
|
|
|
152
213
|
pnpm test:coverage # enforced 100% on covered files
|
|
153
214
|
```
|
|
154
215
|
|
|
155
|
-
Tests run against the real component runtime via `convex-test`
|
|
216
|
+
Tests run against the real component runtime via `convex-test`
|
|
217
|
+
(`@edge-runtime/vm`), not mocks.
|
|
218
|
+
|
|
219
|
+
### Testing your app
|
|
220
|
+
|
|
221
|
+
`@vllnt/convex-email/test` exports `register(t, name = "email")` to mount the
|
|
222
|
+
component in a `convex-test` instance. It needs `convex-test` and `vitest`
|
|
223
|
+
(with Vite's `import.meta.glob`) in the consuming app:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
/// <reference types="vite/client" />
|
|
227
|
+
import { convexTest } from "convex-test";
|
|
228
|
+
import { register } from "@vllnt/convex-email/test";
|
|
229
|
+
import schema from "./schema";
|
|
230
|
+
|
|
231
|
+
const t = convexTest(schema, import.meta.glob("./**/*.ts"));
|
|
232
|
+
register(t);
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Documentation
|
|
236
|
+
|
|
237
|
+
`llms.txt` is the maintained discovery index. `pnpm generate:llms` checks its
|
|
238
|
+
heading and local links without generating a source bundle.
|
|
239
|
+
|
|
240
|
+
[API reference](docs/API.md) · [LLM index](llms.txt) ·
|
|
241
|
+
[Security policy](SECURITY.md)
|
|
156
242
|
|
|
157
243
|
## Contributing
|
|
158
244
|
|
|
@@ -160,9 +246,11 @@ See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
|
160
246
|
|
|
161
247
|
## Author
|
|
162
248
|
|
|
163
|
-
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
249
|
+
Built by [bntvllnt](https://github.com/bntvllnt) ·
|
|
250
|
+
[bntvllnt.com](https://bntvllnt.com) · [X @bntvllnt](https://x.com/bntvllnt)
|
|
164
251
|
|
|
165
|
-
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
252
|
+
Part of the [@vllnt](https://github.com/vllnt) Convex component fleet —
|
|
253
|
+
[vllnt.com](https://vllnt.com)
|
|
166
254
|
|
|
167
255
|
If this is useful, [sponsor the work](https://github.com/sponsors/bntvllnt).
|
|
168
256
|
|
package/dist/component/crons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cronJobs } from "convex/server";
|
|
2
|
-
import { api } from "./_generated/api";
|
|
2
|
+
import { api } from "./_generated/api.js";
|
|
3
3
|
/**
|
|
4
4
|
* Default sweep cadence and page size for the built-in prune cron. The cron is
|
|
5
5
|
* the component's own self-healing safety net — a host that wants a different
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"crons.js","sourceRoot":"","sources":["../../src/component/crons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,KAAK,EAAE,EAAE,EAAW,CAAC;AAErD,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;AAEzB,KAAK,CAAC,QAAQ,CAAC,aAAa,EAAE,cAAc,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;IACjE,KAAK,EAAE,WAAW;CACnB,CAAC,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
* and a message already carries it, the existing message's id is returned and no
|
|
15
15
|
* new row is inserted — a retried enqueue (double-submit, at-least-once delivery)
|
|
16
16
|
* can never produce a duplicate send.
|
|
17
|
+
*
|
|
18
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `messageId`, `to`,
|
|
19
|
+
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string.
|
|
20
|
+
* @throws `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })` when `maxAttempts` is
|
|
21
|
+
* not a positive integer.
|
|
17
22
|
*/
|
|
18
23
|
export declare const enqueue: import("convex/server").RegisteredMutation<"public", {
|
|
19
24
|
from: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAMA
|
|
1
|
+
{"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;GA0ElB,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW;;;;GAmCtB,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ;;;iBAgCnB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU;;;;;;GA8BrB,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK;;;mBA2ChB,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConvexError, v } from "convex/values";
|
|
2
|
-
import { api } from "./_generated/api";
|
|
3
|
-
import { mutation } from "./_generated/server";
|
|
4
|
-
import { DEFAULT_RETENTION_MS, MAX_PRUNE_BATCH } from "../shared";
|
|
5
|
-
import { jsonValue } from "./validators";
|
|
2
|
+
import { api } from "./_generated/api.js";
|
|
3
|
+
import { mutation } from "./_generated/server.js";
|
|
4
|
+
import { DEFAULT_RETENTION_MS, MAX_PRUNE_BATCH } from "../shared.js";
|
|
5
|
+
import { jsonValue } from "./validators.js";
|
|
6
6
|
/**
|
|
7
7
|
* Enqueue an outbound message and return its id immediately — the durable queue
|
|
8
8
|
* entry. The message is inserted in `queued` state with `attempts: 0`,
|
|
@@ -19,6 +19,11 @@ import { jsonValue } from "./validators";
|
|
|
19
19
|
* and a message already carries it, the existing message's id is returned and no
|
|
20
20
|
* new row is inserted — a retried enqueue (double-submit, at-least-once delivery)
|
|
21
21
|
* can never produce a duplicate send.
|
|
22
|
+
*
|
|
23
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `messageId`, `to`,
|
|
24
|
+
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string.
|
|
25
|
+
* @throws `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })` when `maxAttempts` is
|
|
26
|
+
* not a positive integer.
|
|
22
27
|
*/
|
|
23
28
|
export const enqueue = mutation({
|
|
24
29
|
args: {
|
|
@@ -33,6 +38,27 @@ export const enqueue = mutation({
|
|
|
33
38
|
},
|
|
34
39
|
returns: v.object({ messageId: v.string(), deduplicated: v.boolean() }),
|
|
35
40
|
handler: async (ctx, args) => {
|
|
41
|
+
const fields = [
|
|
42
|
+
["messageId", args.messageId],
|
|
43
|
+
["to", args.to],
|
|
44
|
+
["from", args.from],
|
|
45
|
+
["transport", args.transport],
|
|
46
|
+
["idempotencyKey", args.idempotencyKey],
|
|
47
|
+
];
|
|
48
|
+
for (const [name, value] of fields) {
|
|
49
|
+
if (value === "") {
|
|
50
|
+
throw new ConvexError({
|
|
51
|
+
code: "INVALID_ARGUMENT",
|
|
52
|
+
message: `${name} must not be empty`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!Number.isInteger(args.maxAttempts) || args.maxAttempts < 1) {
|
|
57
|
+
throw new ConvexError({
|
|
58
|
+
code: "INVALID_MAX_ATTEMPTS",
|
|
59
|
+
message: "maxAttempts must be a positive integer",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
36
62
|
if (args.idempotencyKey !== undefined) {
|
|
37
63
|
const dupe = await ctx.db
|
|
38
64
|
.query("messages")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"mutations.js","sourceRoot":"","sources":["../../src/component/mutations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,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pB,MAAM,MAAM,GACV,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK;YACtB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;iBACT,KAAK,CAAC,UAAU,CAAC;iBACjB,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,EAAE,CACpC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,CACjD;iBACA,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;YACnC,CAAC,CAAC,EAAE,CAAC;QAET,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC;YACvC,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAE5C,IAAI,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE,CAAC;YAC3B,MAAM,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,EAAE;gBACnD,MAAM;gBACN,KAAK,EAAE,IAAI,CAAC,KAAK;aAClB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
2
|
import { paginationOptsValidator } from "convex/server";
|
|
3
|
-
import { query } from "./_generated/server";
|
|
4
|
-
import { messageStatus, messageView } from "./validators";
|
|
3
|
+
import { query } from "./_generated/server.js";
|
|
4
|
+
import { messageStatus, messageView } from "./validators.js";
|
|
5
5
|
/** Project a stored message row to its public view (drops internal fields). */
|
|
6
6
|
function view(msg) {
|
|
7
7
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../src/component/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG7D,+EAA+E;AAC/E,SAAS,IAAI,CAAC,GAAoB;IAChC,OAAO;QACL,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,cAAc,EAAE,GAAG,CAAC,cAAc;QAClC,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,SAAS,EAAE,GAAG,CAAC,SAAS;KACzB,CAAC;AACJ,CAAC;AAED,6EAA6E;AAC7E,MAAM,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC;IACvB,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,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;QAC3B,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE;aACxB,KAAK,CAAC,UAAU,CAAC;aACjB,SAAS,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;aAC1D,KAAK,CAAC,KAAK,CAAC;aACZ,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACjC,OAAO,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;IACpD,CAAC;CACF,CAAC,CAAC"}
|
package/dist/component/schema.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineSchema, defineTable } from "convex/server";
|
|
2
2
|
import { v } from "convex/values";
|
|
3
|
-
import { jsonValue, messageStatus } from "./validators";
|
|
3
|
+
import { jsonValue, messageStatus } from "./validators.js";
|
|
4
4
|
/**
|
|
5
5
|
* Sandboxed table — the outbound-email queue's own concern. A `messageId` is a
|
|
6
6
|
* host-opaque string that uniquely names one queued message; `to`/`from` are the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/component/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA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
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-canary.d88db7c",
|
|
4
4
|
"description": "Durable, transport-agnostic outbound transactional email queue — enqueue, retry, idempotent send, and per-message delivery status as a Convex component",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"packageManager": "pnpm@
|
|
7
|
+
"packageManager": "pnpm@10.34.8",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"src"
|
|
@@ -53,9 +53,6 @@
|
|
|
53
53
|
"test:coverage": "vitest run --coverage --coverage.reporter=text",
|
|
54
54
|
"generate:llms": "node scripts/generate-llms.mjs",
|
|
55
55
|
"preversion": "pnpm install --frozen-lockfile && pnpm build && pnpm test:coverage && pnpm typecheck && pnpm generate:llms",
|
|
56
|
-
"prepublishOnly": "npm whoami || npm login",
|
|
57
|
-
"alpha": "npm version prerelease --preid alpha && npm publish --tag alpha && git push --follow-tags",
|
|
58
|
-
"release": "npm version patch && npm publish && git push --follow-tags",
|
|
59
56
|
"check:agents": "node -e \"const f=require('node:fs');if(!f.existsSync('AGENTS.md')||f.existsSync('CLAUDE.md')||f.existsSync('.claude'))process.exit(1)\"",
|
|
60
57
|
"codegen": "pnpm convex codegen --component-dir ./src/component"
|
|
61
58
|
},
|
|
@@ -70,19 +67,32 @@
|
|
|
70
67
|
},
|
|
71
68
|
"devDependencies": {
|
|
72
69
|
"@edge-runtime/vm": "^5.0.0",
|
|
73
|
-
"@types/nodemailer": "^8.0.
|
|
70
|
+
"@types/nodemailer": "^8.0.2",
|
|
74
71
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
75
|
-
"@vitest/coverage-v8": "^
|
|
72
|
+
"@vitest/coverage-v8": "^5.0.5",
|
|
76
73
|
"@vllnt/eslint-config": "2.0.0",
|
|
77
74
|
"@vllnt/typescript": "2.0.0",
|
|
78
|
-
"convex": "^1.
|
|
79
|
-
"convex-test": "^0.0.
|
|
75
|
+
"convex": "^1.48.0",
|
|
76
|
+
"convex-test": "^0.0.65",
|
|
80
77
|
"eslint": "^9.39.5",
|
|
81
|
-
"nodemailer": "^
|
|
82
|
-
"prettier": "^3.9.
|
|
78
|
+
"nodemailer": "^10.2.1",
|
|
79
|
+
"prettier": "^3.9.10",
|
|
83
80
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
84
|
-
"vite": "^8.
|
|
85
|
-
"vitest": "^
|
|
81
|
+
"vite": "^8.3.5",
|
|
82
|
+
"vitest": "^5.0.5"
|
|
83
|
+
},
|
|
84
|
+
"pnpm": {
|
|
85
|
+
"minimumReleaseAge": 10080,
|
|
86
|
+
"minimumReleaseAgeExclude": [
|
|
87
|
+
"@vllnt/*"
|
|
88
|
+
],
|
|
89
|
+
"ignoredBuiltDependencies": [
|
|
90
|
+
"esbuild"
|
|
91
|
+
],
|
|
92
|
+
"overrides": {
|
|
93
|
+
"deepmerge-ts@<8.0.0": "8.0.2",
|
|
94
|
+
"handlebars@<4.7.10": "4.7.10"
|
|
95
|
+
}
|
|
86
96
|
},
|
|
87
97
|
"homepage": "https://github.com/vllnt/convex-email#readme",
|
|
88
98
|
"bugs": {
|
package/src/component/crons.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConvexError, v } from "convex/values";
|
|
2
|
-
import { api } from "./_generated/api";
|
|
3
|
-
import { mutation } from "./_generated/server";
|
|
4
|
-
import { DEFAULT_RETENTION_MS, MAX_PRUNE_BATCH } from "../shared";
|
|
5
|
-
import { jsonValue } from "./validators";
|
|
2
|
+
import { api } from "./_generated/api.js";
|
|
3
|
+
import { mutation } from "./_generated/server.js";
|
|
4
|
+
import { DEFAULT_RETENTION_MS, MAX_PRUNE_BATCH } from "../shared.js";
|
|
5
|
+
import { jsonValue } from "./validators.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Enqueue an outbound message and return its id immediately — the durable queue
|
|
@@ -20,6 +20,11 @@ import { jsonValue } from "./validators";
|
|
|
20
20
|
* and a message already carries it, the existing message's id is returned and no
|
|
21
21
|
* new row is inserted — a retried enqueue (double-submit, at-least-once delivery)
|
|
22
22
|
* can never produce a duplicate send.
|
|
23
|
+
*
|
|
24
|
+
* @throws `ConvexError({ code: "INVALID_ARGUMENT" })` when `messageId`, `to`,
|
|
25
|
+
* `from`, `transport`, or a supplied `idempotencyKey` is an empty string.
|
|
26
|
+
* @throws `ConvexError({ code: "INVALID_MAX_ATTEMPTS" })` when `maxAttempts` is
|
|
27
|
+
* not a positive integer.
|
|
23
28
|
*/
|
|
24
29
|
export const enqueue = mutation({
|
|
25
30
|
args: {
|
|
@@ -34,6 +39,27 @@ export const enqueue = mutation({
|
|
|
34
39
|
},
|
|
35
40
|
returns: v.object({ messageId: v.string(), deduplicated: v.boolean() }),
|
|
36
41
|
handler: async (ctx, args) => {
|
|
42
|
+
const fields: Array<[string, string | undefined]> = [
|
|
43
|
+
["messageId", args.messageId],
|
|
44
|
+
["to", args.to],
|
|
45
|
+
["from", args.from],
|
|
46
|
+
["transport", args.transport],
|
|
47
|
+
["idempotencyKey", args.idempotencyKey],
|
|
48
|
+
];
|
|
49
|
+
for (const [name, value] of fields) {
|
|
50
|
+
if (value === "") {
|
|
51
|
+
throw new ConvexError({
|
|
52
|
+
code: "INVALID_ARGUMENT",
|
|
53
|
+
message: `${name} must not be empty`,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (!Number.isInteger(args.maxAttempts) || args.maxAttempts < 1) {
|
|
58
|
+
throw new ConvexError({
|
|
59
|
+
code: "INVALID_MAX_ATTEMPTS",
|
|
60
|
+
message: "maxAttempts must be a positive integer",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
37
63
|
if (args.idempotencyKey !== undefined) {
|
|
38
64
|
const dupe = await ctx.db
|
|
39
65
|
.query("messages")
|
package/src/component/queries.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { v } from "convex/values";
|
|
2
2
|
import { paginationOptsValidator } from "convex/server";
|
|
3
|
-
import { query } from "./_generated/server";
|
|
4
|
-
import { messageStatus, messageView } from "./validators";
|
|
5
|
-
import type { Doc } from "./_generated/dataModel";
|
|
3
|
+
import { query } from "./_generated/server.js";
|
|
4
|
+
import { messageStatus, messageView } from "./validators.js";
|
|
5
|
+
import type { Doc } from "./_generated/dataModel.js";
|
|
6
6
|
|
|
7
7
|
/** Project a stored message row to its public view (drops internal fields). */
|
|
8
8
|
function view(msg: Doc<"messages">) {
|
package/src/component/schema.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineSchema, defineTable } from "convex/server";
|
|
2
2
|
import { v } from "convex/values";
|
|
3
|
-
import { jsonValue, messageStatus } from "./validators";
|
|
3
|
+
import { jsonValue, messageStatus } from "./validators.js";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Sandboxed table — the outbound-email queue's own concern. A `messageId` is a
|