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

notification-service-sdk

v1.0.0

Published

A Node.js notification service SDK supporting email and SMS providers

Readme

Notification Service SDK

一个用于发送通知的Node.js SDK,支持多种通知渠道,包括电子邮件和短信服务。

特性

  • 支持多种通知渠道
    • 电子邮件 (使用Nodemailer)
    • 阿里云短信服务
    • 火山引擎短信服务
    • 华为云短信服务
  • TypeScript支持
  • 简单易用的API
  • 错误处理和日志记录
  • 可扩展的架构

安装

npm install notification-service-sdk

或者使用yarn:

yarn add notification-service-sdk

使用示例

发送电子邮件

import { NotificationService, EmailConfig } from 'notification-service-sdk';

// 配置邮件服务
const emailConfig: EmailConfig = {
  host: 'smtp.example.com',
  port: 587,
  secure: false,
  auth: {
    user: '[email protected]',
    pass: 'your-password'
  }
};

// 创建邮件提供者
const emailProvider = NotificationService.createEmailProvider(emailConfig);

// 发送邮件
async function sendEmail() {
  const result = await emailProvider.send({
    to: '[email protected]',
    subject: '测试邮件',
    text: '这是一封测试邮件',
    html: '<p>这是一封测试邮件</p>'
  });

  if (result.success) {
    console.log('邮件发送成功:', result.messageId);
  } else {
    console.error('邮件发送失败:', result.error);
  }
}

sendEmail();

发送阿里云短信

import { NotificationService, AliSmsConfig } from 'notification-service-sdk';

// 配置阿里云短信服务
const aliSmsConfig: AliSmsConfig = {
  accessKeyId: 'your-access-key-id',
  accessKeySecret: 'your-access-key-secret',
  signName: 'your-sign-name'
};

// 创建阿里云短信提供者
const aliSmsProvider = NotificationService.createAliSmsProvider(aliSmsConfig);

// 发送短信
async function sendSms() {
  const result = await aliSmsProvider.send({
    phoneNumbers: '13800138000',
    templateId: 'SMS_123456789',
    templateParams: {
      code: '123456'
    }
  });

  if (result.success) {
    console.log('短信发送成功:', result.messageId);
  } else {
    console.error('短信发送失败:', result.error);
  }
}

sendSms();

发送火山引擎短信

import { NotificationService, VolcSmsConfig } from 'notification-service-sdk';

// 配置火山引擎短信服务
const volcSmsConfig: VolcSmsConfig = {
  accessKeyId: 'your-access-key-id',
  accessKeySecret: 'your-access-key-secret',
  signName: 'your-sign-name',
  region: 'cn-north-1'
};

// 创建火山引擎短信提供者
const volcSmsProvider = NotificationService.createVolcSmsProvider(volcSmsConfig);

// 发送短信
async function sendSms() {
  const result = await volcSmsProvider.send({
    phoneNumbers: '13800138000',
    templateId: 'SMS_123456789',
    templateParams: {
      code: '123456'
    }
  });

  if (result.success) {
    console.log('短信发送成功:', result.messageId);
  } else {
    console.error('短信发送失败:', result.error);
  }
}

sendSms();

发送华为云短信

import { NotificationService, HuaweiSmsConfig } from 'notification-service-sdk';

// 配置华为云短信服务
const huaweiSmsConfig: HuaweiSmsConfig = {
  endpoint: 'https://sms-api.cn-north-4.myhuaweicloud.com',
  accessKeyId: 'your-access-key-id',
  accessKeySecret: 'your-access-key-secret',
  signName: 'your-sign-name',
  sender: 'your-sender-number'
};

// 创建华为云短信提供者
const huaweiSmsProvider = NotificationService.createHuaweiSmsProvider(huaweiSmsConfig);

// 发送短信
async function sendSms() {
  const result = await huaweiSmsProvider.send({
    phoneNumbers: '13800138000',
    templateId: 'SMS_123456789',
    templateParams: {
      code: '123456'
    }
  });

  if (result.success) {
    console.log('短信发送成功:', result.messageId);
  } else {
    console.error('短信发送失败:', result.error);
  }
}

sendSms();

API文档

NotificationService

静态工厂类,用于创建不同的通知提供者。

方法

  • createEmailProvider(config: EmailConfig): EmailProvider - 创建邮件通知提供者
  • createAliSmsProvider(config: AliSmsConfig): AliSmsProvider - 创建阿里云短信通知提供者
  • createVolcSmsProvider(config: VolcSmsConfig): VolcSmsProvider - 创建火山引擎短信通知提供者
  • createHuaweiSmsProvider(config: HuaweiSmsConfig): HuaweiSmsProvider - 创建华为云短信通知提供者

配置接口

EmailConfig

interface EmailConfig {
  host: string;
  port: number;
  secure?: boolean;
  auth: {
    user: string;
    pass: string;
  };
}

AliSmsConfig

interface AliSmsConfig {
  accessKeyId: string;
  accessKeySecret: string;
  signName: string;
}

VolcSmsConfig

interface VolcSmsConfig {
  accessKeyId: string;
  accessKeySecret: string;
  signName: string;
  region?: string;
}

HuaweiSmsConfig

interface HuaweiSmsConfig {
  endpoint: string;
  accessKeyId: string;
  accessKeySecret: string;
  signName: string;
  sender: string;
}

消息接口

EmailMessage

interface EmailMessage {
  from?: string;
  to: string | string[];
  subject: string;
  text?: string;
  html?: string;
}

BaseSmsMessage

interface BaseSmsMessage {
  phoneNumbers: string | string[];
  templateId: string;
  templateParams?: Record<string, string>;
}

结果接口

SendResult

interface SendResult {
  success: boolean;
  messageId?: string;
  error?: Error;
}

许可证

MIT