@tgoliveira/outpost 1.1.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/AGENTS.md +268 -0
- package/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/adapters/drizzle/index.cjs +405 -0
- package/dist/adapters/drizzle/index.cjs.map +1 -0
- package/dist/adapters/drizzle/index.d.cts +1765 -0
- package/dist/adapters/drizzle/index.d.ts +1765 -0
- package/dist/adapters/drizzle/index.js +387 -0
- package/dist/adapters/drizzle/index.js.map +1 -0
- package/dist/adapters/index.cjs +584 -0
- package/dist/adapters/index.cjs.map +1 -0
- package/dist/adapters/index.d.cts +232 -0
- package/dist/adapters/index.d.ts +232 -0
- package/dist/adapters/index.js +565 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/fake-BY6t7UXb.d.cts +30 -0
- package/dist/fake-en-oOdg0.d.ts +30 -0
- package/dist/http/index.cjs +224 -0
- package/dist/http/index.cjs.map +1 -0
- package/dist/http/index.d.cts +49 -0
- package/dist/http/index.d.ts +49 -0
- package/dist/http/index.js +221 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index-CVUvaJms.d.ts +179 -0
- package/dist/index-Dmt-aLH2.d.cts +179 -0
- package/dist/index.cjs +1387 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +153 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.js +1331 -0
- package/dist/index.js.map +1 -0
- package/dist/outpost-client-yUijE00q.d.cts +271 -0
- package/dist/outpost-client-ymTJISpu.d.ts +271 -0
- package/dist/repositories-Bck6wJNS.d.ts +180 -0
- package/dist/repositories-DhUe8f2R.d.cts +180 -0
- package/dist/services-CQINhAGo.d.cts +90 -0
- package/dist/services-CfTEsetF.d.ts +90 -0
- package/dist/template-CREUq7bB.d.ts +260 -0
- package/dist/template-DxI_p2Ny.d.cts +260 -0
- package/dist/testing/index.cjs +321 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +97 -0
- package/dist/testing/index.d.ts +97 -0
- package/dist/testing/index.js +312 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/webhook-kp6CiXk-.d.cts +149 -0
- package/dist/webhook-kp6CiXk-.d.ts +149 -0
- package/dist/workers/index.cjs +430 -0
- package/dist/workers/index.cjs.map +1 -0
- package/dist/workers/index.d.cts +5 -0
- package/dist/workers/index.d.ts +5 -0
- package/dist/workers/index.js +427 -0
- package/dist/workers/index.js.map +1 -0
- package/package.json +114 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# AGENTS.md — using `@tgoliveira/outpost`
|
|
2
|
+
|
|
3
|
+
> This file is written for AI coding agents (and humans) integrating Outpost into
|
|
4
|
+
> an application. It is the fastest path from "I need to send transactional
|
|
5
|
+
> email reliably" to working code. Read this top-to-bottom once; then jump to the
|
|
6
|
+
> task recipe you need.
|
|
7
|
+
|
|
8
|
+
## What Outpost is (and is not)
|
|
9
|
+
|
|
10
|
+
Outpost is a **transactional outbox with a pluggable transport layer**. Email is
|
|
11
|
+
the only transport in v1. It is **not** an email client and **not** a marketing
|
|
12
|
+
platform. Its job is to guarantee a message is **persisted before it is sent**,
|
|
13
|
+
**deduplicated** (at-most-once), **auditable**, **lifecycle-tracked** via provider
|
|
14
|
+
webhooks, **reputation-safe** (suppression list), and **provider-agnostic**
|
|
15
|
+
(swap Resend ↔ SMTP ↔ SES without touching your code).
|
|
16
|
+
|
|
17
|
+
If you only need "fire an email", a raw provider SDK is simpler. Reach for
|
|
18
|
+
Outpost when losing or duplicating a message is unacceptable (receipts, password
|
|
19
|
+
resets, invoices) and you need an audit trail + delivery tracking.
|
|
20
|
+
|
|
21
|
+
## The one mental model you need
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
your app ──outpost.send()──▶ [outbox table] (persisted FIRST, state=queued)
|
|
25
|
+
│
|
|
26
|
+
SendWorker polls & claims (FOR UPDATE SKIP LOCKED)
|
|
27
|
+
│ decrypt → sanitize → validate → rate-limit
|
|
28
|
+
▼
|
|
29
|
+
EmailProvider.send() → state=sent
|
|
30
|
+
│
|
|
31
|
+
provider webhook (verified) → delivered | bounced | complained
|
|
32
|
+
│
|
|
33
|
+
hard bounce / complaint ──▶ suppression list
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Three rules that explain almost every design choice:
|
|
37
|
+
|
|
38
|
+
1. **Persist before dispatch.** `send()` writes a row, then returns. Nothing is
|
|
39
|
+
sent synchronously. A separate worker sends it later by polling. (No queue is
|
|
40
|
+
written at ingestion — that would risk a dual-write inconsistency.)
|
|
41
|
+
2. **The DB is the source of truth.** State lives in Postgres. Workers are
|
|
42
|
+
stateless loops over it. You can run many workers; row claiming prevents
|
|
43
|
+
double-send.
|
|
44
|
+
3. **PII is encrypted at rest and matched by HMAC.** The recipient and body are
|
|
45
|
+
sealed; suppression/idempotency-by-recipient use a keyed HMAC of the address,
|
|
46
|
+
never plaintext.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm i @tgoliveira/outpost
|
|
52
|
+
# peer deps you actually use:
|
|
53
|
+
npm i drizzle-orm # if using the Postgres adapter
|
|
54
|
+
npm i nodemailer # if using the SMTP/Mailpit provider
|
|
55
|
+
npm i @opentelemetry/api # only if enabling OTel telemetry
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Node ≥ 18.17 (uses global `fetch` and the Web `Request`/`Response`).
|
|
59
|
+
|
|
60
|
+
## Entry points (subpath exports)
|
|
61
|
+
|
|
62
|
+
| Import from | What you get |
|
|
63
|
+
|---|---|
|
|
64
|
+
| `@tgoliveira/outpost` | `createOutpost`, the `Outpost` client, domain types, ports, use cases |
|
|
65
|
+
| `@tgoliveira/outpost/adapters` | Providers (Resend/SMTP/Fake), encryptors, HMAC hasher, rate limiters, logger, telemetry, template renderer |
|
|
66
|
+
| `@tgoliveira/outpost/drizzle` | `outpostSchema`, `DrizzleOutboxRepository` & friends, `OutpostDb` type |
|
|
67
|
+
| `@tgoliveira/outpost/next` | `OutpostRouter` — Fetch-based HTTP handlers for the Next.js App Router |
|
|
68
|
+
| `@tgoliveira/outpost/workers` | `SendWorker`, `RetentionWorker` |
|
|
69
|
+
| `@tgoliveira/outpost/testing` | In-memory repos, `FakeEmailProvider`, `FakeClock`, `inMemoryRepositories()` |
|
|
70
|
+
|
|
71
|
+
## Minimal working example (zero infra — for tests / prototypes)
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { createOutpost } from "@tgoliveira/outpost";
|
|
75
|
+
import { inMemoryRepositories, FakeEmailProvider } from "@tgoliveira/outpost/testing";
|
|
76
|
+
|
|
77
|
+
const outpost = createOutpost({
|
|
78
|
+
repositories: inMemoryRepositories(),
|
|
79
|
+
providers: [new FakeEmailProvider()],
|
|
80
|
+
recipientHmacKey: "a-key-with-at-least-16-bytes-of-entropy",
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await outpost.send({
|
|
84
|
+
idempotencyKey: "welcome-user-42", // REQUIRED — dedupes retries
|
|
85
|
+
to: "user@example.com",
|
|
86
|
+
subject: "Welcome",
|
|
87
|
+
html: "<h1>Hi!</h1>",
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await outpost.tickSend(); // run one send-worker cycle
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Production wiring (Postgres + Resend)
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
97
|
+
import { Pool } from "pg";
|
|
98
|
+
import { createOutpost } from "@tgoliveira/outpost";
|
|
99
|
+
import {
|
|
100
|
+
outpostSchema,
|
|
101
|
+
DrizzleOutboxRepository,
|
|
102
|
+
DrizzleSuppressionRepository,
|
|
103
|
+
DrizzleAuditRepository,
|
|
104
|
+
DrizzleApiKeyRepository,
|
|
105
|
+
DrizzleWebhookEventRepository,
|
|
106
|
+
} from "@tgoliveira/outpost/drizzle";
|
|
107
|
+
import { ResendEmailProvider } from "@tgoliveira/outpost/adapters";
|
|
108
|
+
|
|
109
|
+
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
|
110
|
+
const db = drizzle(pool, { schema: outpostSchema });
|
|
111
|
+
|
|
112
|
+
export const outpost = createOutpost({
|
|
113
|
+
repositories: {
|
|
114
|
+
outbox: new DrizzleOutboxRepository(db),
|
|
115
|
+
suppressions: new DrizzleSuppressionRepository(db),
|
|
116
|
+
audit: new DrizzleAuditRepository(db),
|
|
117
|
+
apiKeys: new DrizzleApiKeyRepository(db),
|
|
118
|
+
webhookEvents: new DrizzleWebhookEventRepository(db),
|
|
119
|
+
},
|
|
120
|
+
providers: [
|
|
121
|
+
new ResendEmailProvider({
|
|
122
|
+
apiKey: process.env.RESEND_API_KEY!,
|
|
123
|
+
from: "Acme <no-reply@acme.com>",
|
|
124
|
+
webhookSecret: process.env.RESEND_WEBHOOK_SECRET!,
|
|
125
|
+
}),
|
|
126
|
+
],
|
|
127
|
+
recipientHmacKey: process.env.OUTPOST_HMAC_KEY!, // from your secret manager
|
|
128
|
+
rateLimits: {
|
|
129
|
+
global: { max: 100, windowMs: 1000 },
|
|
130
|
+
perRecipientDomain: { max: 10, windowMs: 1000 },
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Then run the migration (see `docs/database.md`) and start a worker (see below).
|
|
136
|
+
|
|
137
|
+
## Task recipes
|
|
138
|
+
|
|
139
|
+
### Send a templated message
|
|
140
|
+
```ts
|
|
141
|
+
import { InMemoryTemplateRenderer } from "@tgoliveira/outpost/adapters";
|
|
142
|
+
const templates = new InMemoryTemplateRenderer([
|
|
143
|
+
{ id: "receipt", version: 1, subject: "Receipt {{order}}", html: "<p>Total: {{total}}</p>" },
|
|
144
|
+
]);
|
|
145
|
+
// pass `templates` to createOutpost, then:
|
|
146
|
+
await outpost.send({
|
|
147
|
+
idempotencyKey: "order-1234-receipt",
|
|
148
|
+
to: "customer@example.com",
|
|
149
|
+
template: { id: "receipt", version: 1, vars: { order: "1234", total: "$9.99" } },
|
|
150
|
+
});
|
|
151
|
+
```
|
|
152
|
+
Template variables are HTML-escaped automatically.
|
|
153
|
+
|
|
154
|
+
### Run the send worker
|
|
155
|
+
- **Long-running process** (a worker dyno/container):
|
|
156
|
+
```ts
|
|
157
|
+
outpost.send_worker.start(); // poll loop; outpost.send_worker.stop() to halt
|
|
158
|
+
```
|
|
159
|
+
- **Serverless / cron** (e.g. Vercel Cron hitting a route every minute):
|
|
160
|
+
```ts
|
|
161
|
+
export async function GET() { const r = await outpost.tickSend(); return Response.json(r); }
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Expose the HTTP API in Next.js (App Router)
|
|
165
|
+
```ts
|
|
166
|
+
// app/api/outpost/messages/route.ts
|
|
167
|
+
import { OutpostRouter } from "@tgoliveira/outpost/next";
|
|
168
|
+
import { outpost } from "@/lib/outpost";
|
|
169
|
+
const router = new OutpostRouter(outpost);
|
|
170
|
+
export const POST = (req: Request) => router.enqueue(req); // scope: messages:send
|
|
171
|
+
export const GET = (req: Request) => router.list(req); // scope: messages:read
|
|
172
|
+
```
|
|
173
|
+
Full route table in `docs/nextjs.md`. Every endpoint needs an API key
|
|
174
|
+
(`Authorization: Bearer opk_...`) except the webhook sink.
|
|
175
|
+
|
|
176
|
+
### Receive provider webhooks
|
|
177
|
+
```ts
|
|
178
|
+
// app/api/outpost/webhooks/[provider]/route.ts
|
|
179
|
+
export async function POST(req: Request, { params }: { params: { provider: string } }) {
|
|
180
|
+
return new OutpostRouter(outpost).webhook(req, params.provider);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
The handler reads the **raw body** and verifies the provider signature before
|
|
184
|
+
trusting anything. Configure `webhookSecret` on the provider.
|
|
185
|
+
|
|
186
|
+
### Manage API keys
|
|
187
|
+
```ts
|
|
188
|
+
const { secret } = await outpost.keys.create({ label: "ci", scopes: ["messages:send"] });
|
|
189
|
+
// `secret` is shown ONCE — store it now, it is never recoverable.
|
|
190
|
+
await outpost.keys.revoke(keyId); // takes effect immediately
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Manage the suppression list
|
|
194
|
+
```ts
|
|
195
|
+
await outpost.suppress("user@example.com", "unsubscribe");
|
|
196
|
+
await outpost.isSuppressed("user@example.com"); // true
|
|
197
|
+
await outpost.unsuppress("user@example.com");
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Inspect / replay a dead-lettered message
|
|
201
|
+
```ts
|
|
202
|
+
const msg = await outpost.get(id); // { state: "failed", lastError, attempts, ... }
|
|
203
|
+
await outpost.replay(id); // re-enqueue from the DLQ
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Turn on encryption at rest
|
|
207
|
+
See `docs/security.md`. Quick reference:
|
|
208
|
+
- `encryption: { mode: "symmetric", key: <base64 32 bytes> }` — one key, simplest.
|
|
209
|
+
- `encryption: { mode: "asymmetric", publicKey, privateKey }` — least-privilege
|
|
210
|
+
split (web tier seals with public key, worker opens with private key). Omit
|
|
211
|
+
`privateKey` in the web tier so it physically cannot read bodies back.
|
|
212
|
+
- Bring-your-own KMS: pass `{ sealEncryptor, openEncryptor }` implementing the
|
|
213
|
+
`Encryptor` port.
|
|
214
|
+
|
|
215
|
+
## Hard rules / gotchas (read before you ship)
|
|
216
|
+
|
|
217
|
+
- **`idempotencyKey` is required and is your dedupe key.** Derive it from the
|
|
218
|
+
business event (`order-1234-receipt`), not a random UUID, or retries duplicate.
|
|
219
|
+
- **`send()` does not send.** It enqueues. A worker must be running (loop or
|
|
220
|
+
cron) or nothing leaves the building.
|
|
221
|
+
- **SMTP has no webhooks.** With the SMTP/Mailpit provider, lifecycle stops at
|
|
222
|
+
`sent` — no `delivered`/`bounced`/`complained`. Use Resend/SES/SendGrid for
|
|
223
|
+
delivery tracking.
|
|
224
|
+
- **`recipientHmacKey` is mandatory and must be stable.** Changing it orphans
|
|
225
|
+
every existing suppression entry and breaks recipient lookups. Keep it in a
|
|
226
|
+
secret manager, never in the DB.
|
|
227
|
+
- **Encryption at rest is NOT end-to-end.** The provider receives readable
|
|
228
|
+
content. Outpost protects the DB/backups, not the wire to the provider.
|
|
229
|
+
- **The retention worker redacts by default**, it does not delete: PII columns
|
|
230
|
+
are wiped, the audit row survives. It only touches terminal rows past the
|
|
231
|
+
webhook window.
|
|
232
|
+
- **Delivery semantics.** Idempotency guards prevent duplicate *enqueues* and
|
|
233
|
+
duplicate *dispatch under concurrency*. To survive a worker crashing
|
|
234
|
+
mid-dispatch, a row stuck in `sending` past a lease (default 5 min,
|
|
235
|
+
`staleSendingLeaseMs`) is reclaimed and retried — this is at-least-once at the
|
|
236
|
+
edge. To keep it effectively at-most-once, Outpost passes the message id as the
|
|
237
|
+
provider's idempotency key (e.g. Resend's `Idempotency-Key`), so a reclaim
|
|
238
|
+
cannot double-send through a provider that honors it. Plain SMTP has no such
|
|
239
|
+
key — tune the lease accordingly.
|
|
240
|
+
- **Never use `FakeEmailProvider` or `inMemoryRepositories()` in production** —
|
|
241
|
+
they hold everything in RAM and verify nothing.
|
|
242
|
+
- **API keys are shown once.** Only a hash is stored; there is no "reveal key".
|
|
243
|
+
|
|
244
|
+
## Where to look in the source (Clean Architecture, deps point inward)
|
|
245
|
+
|
|
246
|
+
| Layer | Path | Rule |
|
|
247
|
+
|---|---|---|
|
|
248
|
+
| Domain (pure) | `src/domain/` | No imports outward. Entities, lifecycle state machine, errors. |
|
|
249
|
+
| Ports (interfaces) | `src/ports/` | Imports domain only. The seams to implement. |
|
|
250
|
+
| Application (use cases) | `src/application/` | Imports domain + ports. Orchestration + pipeline. |
|
|
251
|
+
| Adapters (concrete) | `src/adapters/` | Implement ports. Providers, Drizzle, crypto, rate-limit, OTel. |
|
|
252
|
+
| HTTP / Client / Workers | `src/http`, `src/client`, `src/workers` | Edge wiring. |
|
|
253
|
+
| Composition root | `src/create-outpost.ts` | The ONLY place adapters are assembled. |
|
|
254
|
+
|
|
255
|
+
To **add a provider**: implement `EmailProvider` (`src/ports/email-provider.ts`),
|
|
256
|
+
pass it in `providers: [...]`. Nothing in the core changes.
|
|
257
|
+
|
|
258
|
+
To **swap storage**: implement the repository ports
|
|
259
|
+
(`src/ports/repositories.ts`). The Drizzle adapter is one implementation.
|
|
260
|
+
|
|
261
|
+
## Verifying your integration
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
npm test # runs the in-memory end-to-end suite (no infra needed)
|
|
265
|
+
```
|
|
266
|
+
The suite in `test/outpost.test.ts` is also the best worked example of every
|
|
267
|
+
flow: ingestion, idempotency, dispatch, retry/DLQ, webhooks, suppression,
|
|
268
|
+
encryption round-trips, retention, and auth.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Outpost contributors
|
|
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
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Outpost
|
|
2
|
+
|
|
3
|
+
**A transactional outbox with pluggable transport for Next.js.**
|
|
4
|
+
Durable, at-most-once, fully auditable transactional email — with the sending
|
|
5
|
+
provider as a swappable detail.
|
|
6
|
+
|
|
7
|
+
[](https://docs.npmjs.com/generating-provenance-statements)
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createOutpost } from "@tgoliveira/outpost";
|
|
11
|
+
|
|
12
|
+
await outpost.send({
|
|
13
|
+
idempotencyKey: "order-1234-receipt", // dedupes retries
|
|
14
|
+
to: "customer@example.com",
|
|
15
|
+
template: { id: "receipt", version: 3, vars: { name, total } },
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Outpost is **not an email client**. Libraries already send email. Outpost
|
|
20
|
+
guarantees a message is **never lost, delivered at-most-once, fully auditable,
|
|
21
|
+
and provider-independent**. It persists every message before dispatch, processes
|
|
22
|
+
it through a controlled pipeline (sanitization, rate limiting, domain
|
|
23
|
+
validation, encryption-at-rest), tracks its lifecycle via provider webhooks,
|
|
24
|
+
enforces a suppression list, and redacts/retains data per policy.
|
|
25
|
+
|
|
26
|
+
> 🤖 **Integrating with an AI agent?** Read **[AGENTS.md](./AGENTS.md)** — it's
|
|
27
|
+
> the fastest path to working code.
|
|
28
|
+
|
|
29
|
+
## Why
|
|
30
|
+
|
|
31
|
+
A naive `await resend.send(...)` in a request handler can: send twice on retry,
|
|
32
|
+
lose the message if the process dies, keep mailing addresses that hard-bounced
|
|
33
|
+
(burning your sender reputation), and leave no audit trail. Outpost fixes all
|
|
34
|
+
four by making the **database the source of truth** and the **send a separate,
|
|
35
|
+
idempotent, observable step**.
|
|
36
|
+
|
|
37
|
+
## Features (v1)
|
|
38
|
+
|
|
39
|
+
- ✅ **Durable outbox** — persist-before-dispatch; survives crashes.
|
|
40
|
+
- ✅ **At-most-once** — idempotency key required at ingestion, re-checked at dispatch.
|
|
41
|
+
- ✅ **Pluggable transport** — Resend, generic SMTP/Mailpit, in-memory fake; one `EmailProvider` interface.
|
|
42
|
+
- ✅ **Lifecycle tracking** — `queued → sending → sent → delivered | bounced | complained | failed` via verified webhooks.
|
|
43
|
+
- ✅ **Suppression list** — hard bounces & complaints auto-suppress; matched by keyed HMAC.
|
|
44
|
+
- ✅ **Retry + Dead Letter Queue** — exponential backoff with jitter; inspect & replay failures.
|
|
45
|
+
- ✅ **Encryption at rest** — optional AES-256-GCM (symmetric) or RSA-hybrid (asymmetric, least-privilege split). Keys live in KMS, not the DB.
|
|
46
|
+
- ✅ **Append-only audit trail + OpenTelemetry** — on by default.
|
|
47
|
+
- ✅ **Configurable retention** — redact PII, keep audit; batched, terminal-rows-only.
|
|
48
|
+
- ✅ **Authenticated API** — opaque keys with scopes, expiry, and immediate revocation.
|
|
49
|
+
- ✅ **Clean Architecture + SOLID** — testable core, swappable everything.
|
|
50
|
+
|
|
51
|
+
See [the design record](./docs/tdr.md) for scope, security model, and non-goals.
|
|
52
|
+
|
|
53
|
+
## Quick start
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm i @tgoliveira/outpost drizzle-orm pg
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { drizzle } from "drizzle-orm/node-postgres";
|
|
61
|
+
import { Pool } from "pg";
|
|
62
|
+
import { createOutpost } from "@tgoliveira/outpost";
|
|
63
|
+
import { outpostSchema, DrizzleOutboxRepository, DrizzleSuppressionRepository,
|
|
64
|
+
DrizzleAuditRepository, DrizzleApiKeyRepository,
|
|
65
|
+
DrizzleWebhookEventRepository } from "@tgoliveira/outpost/drizzle";
|
|
66
|
+
import { ResendEmailProvider } from "@tgoliveira/outpost/adapters";
|
|
67
|
+
|
|
68
|
+
const db = drizzle(new Pool({ connectionString: process.env.DATABASE_URL }), { schema: outpostSchema });
|
|
69
|
+
|
|
70
|
+
export const outpost = createOutpost({
|
|
71
|
+
repositories: {
|
|
72
|
+
outbox: new DrizzleOutboxRepository(db),
|
|
73
|
+
suppressions: new DrizzleSuppressionRepository(db),
|
|
74
|
+
audit: new DrizzleAuditRepository(db),
|
|
75
|
+
apiKeys: new DrizzleApiKeyRepository(db),
|
|
76
|
+
webhookEvents: new DrizzleWebhookEventRepository(db),
|
|
77
|
+
},
|
|
78
|
+
providers: [new ResendEmailProvider({
|
|
79
|
+
apiKey: process.env.RESEND_API_KEY!,
|
|
80
|
+
from: "Acme <no-reply@acme.com>",
|
|
81
|
+
webhookSecret: process.env.RESEND_WEBHOOK_SECRET!,
|
|
82
|
+
})],
|
|
83
|
+
recipientHmacKey: process.env.OUTPOST_HMAC_KEY!,
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
1. Generate & run the DB migration → [docs/database.md](./docs/database.md).
|
|
88
|
+
2. Wire the HTTP routes → [docs/nextjs.md](./docs/nextjs.md).
|
|
89
|
+
3. Run the send worker → [docs/workers.md](./docs/workers.md).
|
|
90
|
+
|
|
91
|
+
## Documentation
|
|
92
|
+
|
|
93
|
+
| Doc | What's in it |
|
|
94
|
+
|---|---|
|
|
95
|
+
| **[AGENTS.md](./AGENTS.md)** | Agent-first integration guide + task recipes |
|
|
96
|
+
| [docs/getting-started.md](./docs/getting-started.md) | End-to-end setup, dev with Mailpit |
|
|
97
|
+
| [docs/architecture.md](./docs/architecture.md) | Clean Architecture layers, ports, SOLID |
|
|
98
|
+
| [docs/configuration.md](./docs/configuration.md) | Every `createOutpost` option |
|
|
99
|
+
| [docs/api.md](./docs/api.md) | Programmatic + HTTP API reference |
|
|
100
|
+
| [docs/providers.md](./docs/providers.md) | Provider adapters & writing your own |
|
|
101
|
+
| [docs/security.md](./docs/security.md) | Encryption, keys, webhooks, threat model |
|
|
102
|
+
| [docs/database.md](./docs/database.md) | Schema, migrations, indexing |
|
|
103
|
+
| [docs/nextjs.md](./docs/nextjs.md) | App Router route wiring |
|
|
104
|
+
| [docs/workers.md](./docs/workers.md) | Send & retention workers; deployment shapes |
|
|
105
|
+
| [docs/observability.md](./docs/observability.md) | OpenTelemetry & the audit trail |
|
|
106
|
+
| [docs/testing.md](./docs/testing.md) | In-memory repos, fakes, deterministic clock |
|
|
107
|
+
| [docs/adr/](./docs/adr/) | Architecture Decision Records |
|
|
108
|
+
|
|
109
|
+
## Status
|
|
110
|
+
|
|
111
|
+
v1 ships email only; the core is channel-agnostic by design. Phase 2 adds
|
|
112
|
+
automatic provider fallback, more adapters (SES/SendGrid/Postmark), scheduling,
|
|
113
|
+
template versioning, and a second transport to validate the abstraction.
|
|
114
|
+
|
|
115
|
+
## License
|
|
116
|
+
|
|
117
|
+
MIT
|