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

@alimzen/relayo-nestjs

v0.3.0

Published

NestJS module for Relayo: RelayoModule, an injectable RelayoService, @OnRelayoEvent handlers and an optional webhook controller.

Readme

@alimzen/relayo-nestjs

NestJS module for Relayo: configure drivers once, inject RelayoService anywhere, react to delivery events with @OnRelayoEvent(), and receive provider webhooks with a ready-made controller.

npm install @alimzen/relayo @alimzen/relayo-nestjs @alimzen/relayo-sendgrid

Works with NestJS 11 and 12, on Express and Fastify. NestJS 12 is ESM-only: a CommonJS project on NestJS 12 needs Node.js 20.19+ or 22.12+.

Setup

// main.ts: the raw body is needed to verify webhook signatures
const app = await NestFactory.create(AppModule, { rawBody: true });
// app.module.ts
import { failover } from '@alimzen/relayo';
import { RelayoModule } from '@alimzen/relayo-nestjs';
import { sendgrid } from '@alimzen/relayo-sendgrid';
import { ses } from '@alimzen/relayo-ses';

@Module({
  imports: [
    RelayoModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        email: failover([
          ses({ region: 'eu-west-1' }),
          sendgrid({ apiKey: config.getOrThrow('SENDGRID_API_KEY'), webhook: { publicKey: config.getOrThrow('SENDGRID_WEBHOOK_KEY') } }),
        ]),
      }),
      webhooks: true,
    }),
  ],
})
export class AppModule {}

RelayoModule.forRoot({ email, sms, webhooks }) does the same with static options. The module is global by default (isGlobal: false to opt out).

Sending and handling events

import { OnRelayoEvent, RelayoService } from '@alimzen/relayo-nestjs';
import type { BounceEvent, RelayoEvent } from '@alimzen/relayo';

@Injectable()
export class InvoiceMailer {
  constructor(private readonly relayo: RelayoService) {}

  send(invoice: Invoice) {
    return this.relayo.email.send({
      from: { address: '[email protected]' },
      to: { address: invoice.customerEmail },
      subject: `Invoice ${invoice.number}`,
      html: renderInvoice(invoice),
      metadata: { invoiceId: invoice.id },
    });
  }

  @OnRelayoEvent('bounced')
  async onBounce(event: BounceEvent) {
    if (event.bounceType === 'hard') await this.contacts.markInvalid(event.recipient);
  }

  @OnRelayoEvent('complained', 'unsubscribed')
  async onOptOut(event: RelayoEvent) {
    await this.contacts.stopSending(event.recipient);
  }
}

@OnRelayoEvent() takes one or more event types, or '*' for all, and works on singleton providers and controllers. Request-scoped classes are skipped with a warning. At startup the module logs every handler it subscribed:

[RelayoModule] @OnRelayoEvent handlers: InvoiceMailer.onBounce (bounced), InvoiceMailer.onOptOut (complained, unsubscribed)

If a handler you expect is not in that line, its class is not registered in a module (providers or controllers). If it is listed but never runs, the events are not reaching this module's instance: receive webhooks with webhooks: true or RelayoService.handleWebhook(), not with a separate createRelayo(). RelayoService has the same API as the Relayo instance (email, sms, account(), accounts, on, off, emit, handleWebhook); the RELAYO_CLIENT token gives you the instance itself.

Several accounts go in the module options too, RelayoModule.forRoot({ email: ses(...), accounts: { marketing: { email: smtp(...) } } }), and are used with this.relayo.account('marketing').email.send(...).

Webhooks

With webhooks: true (or { path: 'hooks/mail' }) the module adds:

  • POST /webhooks/relayo/:channel, e.g. /webhooks/relayo/email
  • POST /webhooks/relayo/:channel/:provider, e.g. /webhooks/relayo/email/sendgrid. Use this form with failover(), one URL per provider.
  • ?account=<name> on either route for webhooks of a named account, e.g. /webhooks/relayo/email?account=marketing. Unknown accounts get a 400.

| Response | When | | --- | --- | | 200 { received: n } | Events verified, normalized and handled | | 401 | Signature check failed | | 400 | Unknown channel or payload the driver doesn't understand | | 500 | A handler threw. The provider will deliver the webhook again, so handlers should be idempotent (use event.id) |

The controller reads req.rawBody (enable rawBody: true). JSON posted as text/plain, as Amazon SNS does, is read too. If a signature fails and no raw body was available, the module logs a hint once.