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

@meta-1/nest-message

v0.0.12

Published

NestJS Message module for mail services and code verification

Readme

@meta-1/nest-message

Message service library for NestJS applications including email sending, verification code management, and more.

✨ Features

  • 📧 Email Service - Support for AWS SES and Aliyun DirectMail
  • 🔐 Verification Code - Redis-based verification code management
  • 🎯 Error Codes - Type-safe error code definitions

📦 Installation

npm install @meta-1/nest-message
# or
pnpm add @meta-1/nest-message
# or
yarn add @meta-1/nest-message

🚀 Usage

Module Setup

First, import and configure the MessageModule in your application module:

import { Module } from '@nestjs/common';
import { MessageModule } from '@meta-1/nest-message';

@Module({
  imports: [
    // Using AWS SES
    MessageModule.forRoot({
      debug: false,
      mail: {
        type: 'aws-ses',
        ses: {
          accessKeyId: 'your-access-key-id',
          accessKeySecret: 'your-secret-access-key',
          region: 'us-east-1',
          fromEmail: '[email protected]'
        }
      }
    }),
    
    // Or using Aliyun DirectMail
    MessageModule.forRoot({
      debug: false,
      mail: {
        type: 'alc-dm',
        dm: {
          accessKeyId: 'your-access-key-id',
          accessKeySecret: 'your-secret-access-key',
          region: 'cn-hangzhou',
          fromEmail: '[email protected]',
          fromAlias: 'My Application'
        }
      }
    })
  ]
})
export class AppModule {}

Email Service

import { MailService } from '@meta-1/nest-message';

@Injectable()
export class UserService {
  constructor(private readonly mailService: MailService) {}

  async sendWelcomeEmail(email: string) {
    await this.mailService.sendEmail({
      to: email,
      subject: 'Welcome!',
      html: '<h1>Welcome to our platform!</h1>',
    });
  }
}

Verification Code Service

import { MailCodeService } from '@meta-1/nest-message';

@Injectable()
export class AuthService {
  constructor(private readonly mailCodeService: MailCodeService) {}

  async sendVerificationCode(email: string) {
    await this.mailCodeService.send({
      email,
      action: 'register',
    });
  }

  async verifyCode(email: string, code: string) {
    const isValid = await this.mailCodeService.verify(
      email,
      'register',
      code
    );
    
    if (!isValid) {
      throw new Error('Invalid verification code');
    }
  }
}

🚨 Error Codes

The message module defines its own error codes in the range 1000-1999.

Import

import { AppError } from '@meta-1/nest-common';
import { MessageErrorCode } from '@meta-1/nest-message';

Verification Code Errors (1000-1099)

| Error Code | Code | Message | |-----------|------|---------| | VERIFICATION_CODE_STORAGE_FAILED | 1000 | Verification code storage failed | | EMAIL_SENDING_FAILED | 1001 | Email sending failed | | VERIFICATION_CODE_SEND_FAILED | 1002 | Failed to send verification code | | VERIFICATION_CODE_EXPIRED | 1003 | Verification code expired or does not exist | | VERIFICATION_CODE_INCORRECT | 1004 | Verification code incorrect |

Mail Service Errors (1100-1199)

| Error Code | Code | Message | |-----------|------|---------| | MAIL_SERVICE_NOT_CONFIGURED | 1100 | Mail service not configured correctly | | MAIL_CONTENT_EMPTY | 1101 | Email content cannot be empty |

Usage Example

import { AppError } from '@meta-1/nest-common';
import { MessageErrorCode } from '@meta-1/nest-message';

@Injectable()
export class MailCodeService {
  async send(email: string) {
    try {
      await this.redis.setex(key, 300, code);
    } catch (error) {
      // Use predefined error code
      throw new AppError(MessageErrorCode.VERIFICATION_CODE_STORAGE_FAILED);
    }
  }
  
  async verify(email: string, code: string) {
    const storedCode = await this.redis.get(key);
    
    if (!storedCode) {
      // Error code includes both code and message
      throw new AppError(MessageErrorCode.VERIFICATION_CODE_EXPIRED);
    }
    
    if (storedCode !== code) {
      throw new AppError(MessageErrorCode.VERIFICATION_CODE_INCORRECT);
    }
  }
}

📝 API Reference

Classes

  • MailService - Email sending service with AWS SES and Aliyun DirectMail support
  • MailCodeService - Verification code management service with Redis

Error Codes

  • MessageErrorCode - Type-safe error code definitions for the message module

Types

  • MessageErrorCodeType - TypeScript type for all message error codes
  • MessageErrorCodeValue - Union type of all error code values

📄 License

MIT