@volter/twin-postmark
v0.1.37
Published
Local Postmark twin — a faithful, stateful local Postmark transactional-email API your real `postmark` SDK talks to unmodified. Plain/templated/batch sends, outbound + inbound message activity, bounces and delivery stats, templates, message streams, suppr
Readme
@volter/twin-postmark
A local Postmark twin — a faithful, stateful local Postmark transactional-email API your
real postmark SDK talks to unmodified. Send plain/templated/batch email; browse outbound
message activity with per-message delivery events; bounces + delivery stats; templates with
Mustachio rendering; message streams; suppressions; webhooks; servers, domains and sender
signatures. A deterministic offline delivery lifecycle writes real MessageEvents, mints
Bounce records and suppressions, and POSTs Postmark's real (unsigned, Basic-auth/custom-header)
webhook payloads to your registered endpoints. Ships a React activity mirror UI rendered
from real twin state. Built on the shared @volter/world-core kernel
(append-only event log + projection, local-action writes, egress ledger, connectors, pack
registry).
import { ServerClient, Models } from 'postmark';
import { createPostmarkTwinServer } from '@volter/twin-postmark';
const twin = createPostmarkTwinServer({ port: 0 }); // local, offline
// The SDK's OWN public option points it at the twin — nothing is monkey-patched.
const postmark = new ServerClient(
'11111111-2222-3333-4444-555555555555',
new Models.ClientOptions.Configuration(false, `127.0.0.1:${twin.port}`, 30),
);
const sent = await postmark.sendEmail({
From: 'Acme <[email protected]>',
To: '[email protected]',
Subject: 'Your login code',
TextBody: 'Your code is 123456',
}); // → { MessageID, SubmittedAt, ErrorCode: 0, Message: 'OK' }
const details = await postmark.getOutboundMessageDetails(sent.MessageID);
details.MessageEvents; // → [{ Type: 'Delivered', … }]Zero-edit redirection also works: set POSTMARK_TWIN_URL and the control-plane injector
forwards api.postmarkapp.com to the twin, so an unchanged app finds it with no config.
CLI
world-postmark serve [--port N] [--root DIR] [--read-only] # the Postmark API twin
world-postmark mirror [--port N] [--root DIR] # the activity mirror UI
world-postmark conformance [--root DIR] # spec-true validationHow it works
- A repo, not a mock. Every write is a local action appended to the kernel's log; every
read folds the projection. A sent message is stored in twin state — never put on the
wire — and
GET /messages/outboundserves the same projection the mirror renders. - Auth is Postmark's, faked locally.
X-Postmark-Server-Tokenon server-scoped routes andX-Postmark-Account-Tokenon account-scoped ones (not a Bearer token). A twin holds no account, so any non-empty token is accepted; a missing or empty one fails like the vendor with401 {ErrorCode: 10}and the vendor's endpoint-scoped message text. The documented public test tokenPOSTMARK_API_TESTis modeled with its real/email-only restriction. - A deterministic offline delivery lifecycle. A send records
MessageEventson the stored message:Delivered, plusOpened/LinkClickedonly when the message asked for that tracking (Postmark's tracking is opt-in). A recipient whose local part starts withbouncehard-bounces;spam/complaintraises a spam complaint. Both mint a real Bounce record and a suppression, so a later send to that address is refused with the vendor's422 {ErrorCode: 406}— genuinely stateful behavior, not a fresh-root trick. - Webhooks are Postmark's, which means UNSIGNED. There is no svix/HMAC scheme anywhere in
Postmark's design. Deliveries carry a
RecordTypediscriminator (Delivery/Open/Click/Bounce/SpamComplaint) and are authenticated the two ways the Webhooks API actually models:HttpAuth→ an HTTP Basic header, andHttpHeaders→ your own headers. A webhook only receives a record type whose trigger is enabled, on its own message stream.postmark.honesty.no_webhook_signatureis a deliberate negative assertion that keeps a future contributor from copying a sibling pack's signature scheme in here. - The mirror is API passthrough (archetype A). The browser client fetches Postmark's own real API paths; there is exactly one handler serving both the screen and the SDK, so API↔UI parity cannot drift.
Coverage
Partial and honest, and it is meant to read that way. The capability manifest
(src/postmark-capabilities.ts) is the real vendor surface as the denominator — all 15
documented API groups and 86 endpoints from developer.postmarkapp.com's docs nav, enumerated
top-down whether or not this twin has reached them. Coverage grows by building, and the
percentage drops when the denominator honestly grows. See the generated table in the repo
README for the live numbers.
Where the surface came from (recorded in spec-sources.json as kind: "none" — Postmark
publishes no OpenAPI/SDL):
- The official
postmarknpm SDK v4.0.7's compiled route map and TypeScript models — a first-party artifact naming every path, verb, field, casing and list envelope, plus itsAuthHeaderNamesenum andApiInputError.ERROR_CODES. - developer.postmarkapp.com's published API-error-codes table (163 rows) — the source of
every
ErrorCode/HTTP-status pair inPOSTMARK_ERRORS. - Live read-only probes of
api.postmarkapp.comwith the documented public test token, made during this pack's build. These corrected three things the docs alone get wrong, each annotated[WIRE]inpostmark-twin.ts:Subjectis NOT required onPOST /email— a subject-less send succeeds;- the 401 message text is endpoint-scoped ("valid Server token" vs "valid Account token"), not the merged string the docs table shows;
POSTMARK_API_TESTis/email-only, answering403+ErrorCode 10anywhere else, and"Test job accepted"rather than"OK"on a send.
Anything not grounded in those three is marked ⚠ doc-unverified in the source and never
claimed beyond what a verify() proves.
Fidelity quirks deliberately preserved
Postmark's API is inconsistent in ways a tidy-minded twin would silently "fix". These are modeled as-is, because a consumer's parsing depends on them:
TotalCountcomes first on every list envelope except/message-streams(last) and/webhooks(absent entirely)./sendersreturns aSenderSignaturesarray, notSenders./deliverystats's first bounce row is the"All"total and carries noTypekey.- Batch sends answer HTTP 200 with per-message errors inside a bare array — never a top-level 422 (only the >500 cap is).
- Suppression deletion is a POST to
…/suppressions/delete, not an HTTPDELETE. - "Not found" for a known route is 422 + a per-domain
ErrorCode, not 404; 404 is reserved for a route that does not exist at all. - An outbound message mixes two recipient shapes in one payload:
To/Cc/Bccare arrays of{Email, Name}objects whileRecipients, right beside them, is an array of plain email strings (all of To+Cc+Bcc flattened). This is the vendor's real shape, not a twin bug — grounded in the outbound-search example on postmarkapp.com/developer/api/messages-api ("To":[{"Email":…,"Name":…}]next to"Recipients":["…"]) and the officialpostmarkSDK's own types (OutboundMessage.To: Recipient[]vsRecipients: string[]), and pinned bypostmark.messages.outbound_recipient_shapesso neither side is ever "fixed" into consistency. (One sub-shape divergence, recorded honestly: for a bare address with no display name the docs example shows"Name": nullwhere this twin emits""— the string the official SDK's non-nullableName: stringtype declares.)
No UI mirror? — it has one, and here is the rule it was decided by
Postmark's core job is done in code (an integrator calls POST /email), so ui-scope.json
records needsUi: false: it is not an agent navigation target. The mirror exists as a
state visualization — the local-dev outbox where a human inspects what the twin stored,
which is exactly what Postmark's Activity dashboard is for. Same classification and same
reasoning as the sibling resend pack. Every UI capability is data-coupled (seed through
the twin's write path → fetch the same API the screen reads → assert), never a marker grep.
Known gaps (filed, not hidden)
Tracked as todo capabilities and in pull-audit.json: the Bulk API lifecycle, real inbound
ingestion, PUT /templates/push, webhook verify/statistics, full Mustachio blocks
({{#each}}/{{#if}}) and layout composition, the rate-limit response headers and 429 path,
the 415 problem+json envelope, and connector pulls for account-token domains/sender
signatures, stream-scoped suppressions, inbound messages, and >500-row pagination.
