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

@mailkite/better-auth-inbox

v0.4.0

Published

Give a Better Auth app a real mailbox — receive email as signature-verified webhooks, list and read messages, and reply, scoped per user or per organization.

Downloads

437

Readme

@mailkite/better-auth-inbox

Give a Better Auth app a real mailbox.

Every email surface Better Auth ships is outbound — a magic link, an OTP, an invitation. When someone replies, there is nowhere for it to land. This plugin adds the other half: your app receives email as signature-verified webhooks, stores it against the owning user or organization, and lets the browser read and reply through session-authenticated endpoints.

No auth library offers this. Neither does Resend, nor @better-auth/infra.

npm install @mailkite/better-auth-inbox

Setup

import { betterAuth } from "better-auth";
import { mailkiteInbox } from "@mailkite/better-auth-inbox";

export const auth = betterAuth({
  plugins: [
    mailkiteInbox({
      apiKey: process.env.MAILKITE_API_KEY!,
      domain: "acme.com",                    // verified for receiving
      webhookSecret: process.env.MAILKITE_WEBHOOK_SECRET!,
      baseURL: "https://acme.com",           // where MailKite POSTs deliveries
    }),
  ],
});

Run your migration (npx @better-auth/cli migrate) to create the two tables, then point the domain's webhook at /api/auth/mailkite/inbox/webhook.

Client

import { createAuthClient } from "better-auth/client";
import { mailkiteInboxClient } from "@mailkite/better-auth-inbox/client";

const client = createAuthClient({ plugins: [mailkiteInboxClient()] });

The browser never holds a MailKite API key — every call is session-authenticated against your own auth server, which does the privileged work.

Endpoints

| Route | Auth | What | |---|---|---| | POST /mailkite/inbox/webhook | signature | Inbound delivery from MailKite | | POST /mailkite/inbox/provision | session | Claim an address for the user or their active org | | GET /mailkite/inbox/mailboxes | session | The caller's addresses — so an app can show "your address" after a reload | | GET /mailkite/inbox/messages | session | List readable messages, newest first. Pass mailboxId to scope to one address | | GET /mailkite/inbox/message?id= | session | Read one, marks it read | | POST /mailkite/inbox/reply | session | Reply from the mailbox that received it |

Per-organization inboxes

With Better Auth's organization plugin, pass forOrganization: true and the mailbox belongs to the session's active organization rather than the user — so every member of that org shares one inbox, and switching orgs switches the mail.

await client.mailkite.inbox.provision({ localPart: "support", forOrganization: true });

Reacting to mail

mailkiteInbox({
  // …
  onMessage: async (message) => {
    await notifySlack(message.subject);
  },
});

A throwing handler does not fail the webhook. The message is already stored, and a non-2xx would make MailKite redeliver mail you already hold.

Options

| Option | Notes | |---|---| | apiKey | Required. MailKite API key. | | domain | Required. Domain addresses are provisioned on. | | webhookSecret | Required. Unsigned webhooks are never accepted. | | baseURL | Public URL of the app; needed to register inbound routes. | | toleranceSeconds | Replay window. Default 300. | | onMessage | Runs after a message is stored. | | baseUrl · fetch · now | Overrides for staging and tests. |

Security

This is multi-tenant mail, so the boundaries are the product:

  • One access rule, one place. Every read resolves through the same readableMailboxes check — the caller's own mailboxes plus their active organization's. Endpoints never filter ad hoc.
  • Webhooks are HMAC-SHA256 verified over {timestamp}.{payload}, compared in constant time, with a timestamp window so a captured delivery can't be replayed forever.
  • Foreign resources 404, never 403. A 403 confirms the id exists. The response for "no such message" and "not yours" is byte-identical, including for callers who own no mailbox at all — there is a regression test asserting exactly that.
  • Replies send from the mailbox, never the caller's address — the mailbox is the identity the other party already knows.
  • Redelivery is idempotent, keyed on MailKite's message id.

License

MIT