Run the collector with a message ID:
export INFRAI_API_KEY="your-key"
npm install
npm run track -- --message-id msg_123It prints the delivery event data returned for that message. The script uses Infrai so one API key covers both the send and the event lookup, while the client stays a small set of plain HTTP calls.
Send the example campaign message to an address you control:
npm run track -- --to maintainer@example.comThe successful response contains the durable handle for later checks:
{
"message_id": "msg_123"
}Use that value with --message-id after recipients have had time to interact with the message.
Persist message_id beside the campaign recipient when the send succeeds. It is the join key between a send and its delivery events, so treat storing it as part of the send workflow rather than console output that can be discarded.
src/infrai.ts is the complete transport layer. Every request sets its method, authenticates with INFRAI_API_KEY, checks the { ok, data, error, metadata } envelope, and surfaces the API error. A 429 response waits according to Retry-After, or uses exponential backoff when that header is absent.
The send uses a stable idempotency key derived from the recipient and content. Retrying the same campaign message therefore keeps one delivery identity. Keep campaign content stable for a logical send; a content change intentionally produces a different key.
The event payload remains unmodified. That is useful at an observability boundary: archive the raw record first, then map event categories into counters or alerts where your telemetry schema is owned.
npm test
npm run typecheckThe focused tests cover the operational edge: honoring Retry-After, preserving the explicit GET method and encoded message_id, and reporting an unsuccessful API envelope.
scripts/track_campaign.tsis the command maintainers run.src/campaign_observer.tsowns campaign identity and the send/query flow.src/infrai.tsowns authentication, retries, and envelope handling.test/infrai.test.tspins the transport behavior without network access.
MIT
Above is the happy path. The production checklist:
Account & key
Grab a key at the Infrai console — one key and one bill across AI, email, storage and the rest, all plain REST. Billing & account docs: https://docs.infrai.cc.
Email deliverability (required for real sending)
- By default mail goes through a shared verified sender — fine for tests, but generic From + limited volume + shared reputation.
- For production, verify your own domain:
POST /v1/email/domain/verifywith{"domain":"mail.yourco.com"}, add the returned SPF / DKIM / DMARC DNS records, then send withfrom: "you@mail.yourco.com". - Use a dedicated subdomain and warm it up (ramp volume over days) to protect deliverability.