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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@memo28.pro/notification

v0.0.3

Published

企业级消息通知解决方案 - 支持多平台消息推送的轻量级 TypeScript SDK

Readme

@memo28.pro/notification

npm version License: ISC TypeScript

🚀 企业级消息通知解决方案 - 支持多平台消息推送的轻量级 TypeScript SDK

✨ 特性

  • 🎯 多平台支持: 企业微信、飞书、钉钉等主流平台
  • 🔧 插件化架构: 易于扩展和自定义
  • 📝 消息构建器: 支持文本、Markdown 等多种格式
  • 🛡️ 类型安全: 完整的 TypeScript 类型定义
  • 轻量高效: 零依赖,体积小巧
  • 🧪 完整测试: 单元测试和集成测试覆盖

📦 安装

# npm
npm install @memo28.pro/notification

# yarn
yarn add @memo28.pro/notification

# pnpm
pnpm add @memo28.pro/notification

🚀 快速开始

基础用法

import { Core, MessageBuilder, Wxcom } from '@memo28.pro/notification';

// 创建核心实例
const core = new Core();

// 创建消息构建器
const msgBuilder = MessageBuilder.create()
  .setText('🚀 Hello World!')
  .setMarkdown('# 标题\n\n**粗体文本**');

// 创建企业微信插件
const wxcomPlugin = new Wxcom('YOUR_WEBHOOK_URL');

// 注册插件并发送消息
core.registerModule(wxcomPlugin);
core.seed(msgBuilder);

// 发送消息
const result = await wxcomPlugin.send();
console.log('发送结果:', result);

高级用法

import { Core, MessageBuilder, Wxcom } from '@memo28.pro/notification';

// 创建多个插件实例(发送到不同群组)
const wxcomPlugin1 = new Wxcom('WEBHOOK_URL_1');
const wxcomPlugin2 = new Wxcom('WEBHOOK_URL_2');

// 构建复杂消息
const msgBuilder = MessageBuilder.create()
  .setText('📢 系统通知')
  .setMarkdown(`
# 📊 系统状态报告

## 服务状态
- **API服务**: ✅ 正常
- **数据库**: ✅ 正常
- **缓存**: ⚠️ 警告

## 统计信息
- 在线用户: **1,234**
- 今日访问: **12,345**

---
*报告时间: ${new Date().toLocaleString()}*
  `)
  .setText('📝 如有问题请及时处理');

// 注册多个插件
const core = new Core();
core.registerModule([wxcomPlugin1, wxcomPlugin2]);
core.seed(msgBuilder);

// 批量发送
const results = await Promise.all([
  wxcomPlugin1.send(),
  wxcomPlugin2.send()
]);

console.log('发送结果:', results);

📚 API 文档

Core 类

核心管理类,负责插件注册和消息分发。

class Core {
  // 注册单个或多个插件
  registerModule(module: Base | Base[]): void;
  
  // 播种消息到所有已注册的插件
  seed(msgBuilder: MessageBuilder): void;
  
  // 获取已注册插件数量
  getModuleCount(): number;
}

MessageBuilder 类

消息构建器,支持链式调用构建多种格式的消息。

class MessageBuilder {
  // 创建新的消息构建器实例
  static create(): MessageBuilder;
  
  // 添加文本消息
  setText(text: string): MessageBuilder;
  
  // 添加 Markdown 消息
  setMarkdown(markdown: string): MessageBuilder;
  
  // 获取消息数量
  getMessageCount(): number;
  
  // 获取所有消息
  getMessages(): MessageBuilderPayload[];
  
  // 清空所有消息
  clear(): MessageBuilder;
}

Wxcom 类

企业微信插件,实现企业微信 Webhook 消息发送。

class Wxcom extends Base {
  // 构造函数
  constructor(webhook?: string);
  
  // 设置 Webhook 地址
  setWebhook(webhook: string): void;
  
  // 发送消息
  send(): Promise<boolean>;
  
  // 获取插件名称
  getName(): string;
}

🔌 插件开发

你可以通过继承 Base 类来开发自定义插件:

import { Base, MessageBuilderPayload } from '@memo28.pro/notification';

class CustomPlugin extends Base {
  constructor(private config: any) {
    super();
  }
  
  getName(): string {
    return 'custom';
  }
  
  async send(): Promise<boolean> {
    try {
      // 获取消息列表
      const messages = this.getMessages();
      
      // 实现你的发送逻辑
      for (const message of messages) {
        await this.sendMessage(message);
      }
      
      return true;
    } catch (error) {
      console.error('发送失败:', error);
      return false;
    }
  }
  
  private async sendMessage(message: MessageBuilderPayload): Promise<void> {
    // 根据消息类型实现具体发送逻辑
    switch (message.type) {
      case 'text':
        // 发送文本消息
        break;
      case 'markdown':
        // 发送 Markdown 消息
        break;
    }
  }
}

🧪 测试

# 运行所有测试
npm test

# 运行测试并监听文件变化
npm run test:watch

# 运行测试 UI
npm run test:ui

📋 系统架构

graph TD
    A[Core SDK] --> B[Plugin Adapter]
    B --> C[WeCom Plugin]
    B --> D[Lark/Feishu Plugin]
    B --> E[Custom Plugin]
    A --> F[Message Builder]
    A --> G[Token Manager]
    A --> H[Error Handler]

🤝 贡献

欢迎提交 Issue 和 Pull Request!

  1. Fork 本仓库
  2. 创建你的特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交你的修改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开一个 Pull Request

📄 许可证

本项目采用 ISC 许可证。

🔗 相关链接