npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@btravstack/mailer

v0.50.0

Published

A Mailer port for @btravstack/core: a recording adapter a spec asserts against, an SMTP adapter, and a composition that spans, counts and logs every send

Readme

@btravstack/mailer

The mail port for @btravstack/core: one Mailer an application depends on, a recording adapter a spec asserts against, an SMTP adapter, and a span, a count and a log line per send.

📖 Documentation · API Reference

pnpm add @btravstack/mailer @btravstack/core @btravstack/config @btravstack/di unthrown

Four peer dependencies, plus nodemailer — optional, and needed only if you compose the SMTP adapter. Instrumentation needs no peer of its own: the Logger, Tracer and Meter it depends on are the kernel's ports. Node >=22.

A worked example

A notification, and the failure arm that makes it honest:

import { Mailer } from "@btravstack/mailer";
import { Port, Provider } from "@btravstack/di";
import type { AsyncResult } from "unthrown";

class Notifier extends Port("ReadmeNotifier")<{
  readonly placed: (
    to: string,
    orderId: string,
  ) => AsyncResult<void, RetryableError>;
}> {}

export const notifier = Provider(Notifier)({
  inject: { mailer: Mailer },
  sync: ({ mailer }) => ({
    placed: (to, orderId) =>
      mailer
        .send({
          from: "[email protected]",
          to: [to],
          subject: `order ${orderId} placed`,
          text: `Order ${orderId} is on its way.`,
        })
        // A failed send is YOUR transport's problem, which is why the port
        // models it instead of retrying: leaving the delivery un-acked
        // hands it to the next worker, on the broker's own budget.
        .mapErrCases((matcher) =>
          matcher.with(
            P.tag("MailNotSent"),
            (error) =>
              new RetryableError(
                `order ${orderId} was not notified: ${error.reason}`,
              ),
          ),
        ),
  }),
});

The composition — the adapter is the only decision, made here and nowhere else:

import { mailer } from "@btravstack/mailer";
import { smtpMailer } from "@btravstack/mailer/smtp";

export const NotifierApp = Module("NotifierApp")({
  imports: [
    // Instrumented by default: a span, a counter and a log line per send,
    // which is why `observability()` and `otel()` are below. Pass
    // Every call is reported through `Observers`. Drop the two modules
    // below and this composition is unchanged — it just reports to nobody.
    mailer({ adapter: smtpMailer() }),
    observability(),
    otel(),
  ],
  provides: [notifier],
  exports: [Notifier, Logger],
});

And in a test, the adapter that sends nothing and keeps everything:

import { mailRecorder, recordingMailerProvider } from "@btravstack/mailer";
import { overridden } from "@btravstack/testing";

const recorder = mailRecorder();
const app = overridden(NotifierApp, [recordingMailerProvider(recorder)]);
// … place an order through the real graph …
expect(recorder.only()).toEqual(
  expect.objectContaining({ subject: "order 42 placed" }),
);

Options

| Option | Where | What it is | | ---------- | ----------------------------------- | ------------------------------------------------------- | | adapter | mailer({ adapter }) | the adapter module providing MailerBackend — required | | SMTP_URL | environment, read by smtpMailer() | the transport URL — required, validated at graph build |

The full table — defaults, semantics and the reasoning — lives on the reference page, which is this list's one detailed home.

What it decides, and what it does not

It decides that every send is handed to whatever contributed to Observers — there is no flag and no opt-out, because a graph that composed no observability pays one inert call and reports to nobody. It decides that the SMTP adapter contributes a health check — verify(), a connection and an authentication, folded into the kernel's /healthz with nothing wired, while the recording adapter contributes none because it would report healthy for free. And it decides that a send is accepted, not delivered, and that a failure is a modeled MailNotSent carrying the envelope and never the body.

It does not decide what happens after a failure — retrying belongs to your transport, and the example answers a RetryableError so the broker's budget owns it. Mail carries the whole envelope — cc, bcc, attachments and headers beside to, subject and the two bodies — but there is no templating, no bulk send and no address validation — each reason is on the reference page, and the same reasoning is in AGENTS.md for contributors.

License

MIT