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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@node-notifications/core

v3.1.0

Published

Notification System Core

Downloads

276

Readme

Notification System Core Package

Description

Core package for Notification System

Install

yarn add @node-notifications/core

Documentation

The Core module provide basic notifications/queue logic and interfaces:

  • Notification service with queue;
  • Notification history;
  • Configurable "Resend Strategy";
  • Configurable "Leaky Bucket" provides transport limitation of send count per (time or by try);

Services

  • NotificationService: Base service for sending/processing notifications;
  • NotificationQueueManager: Background queue processing service. If it isn't used, you must to manually call NotificationService::processQueue() periodically;

Default configuration of NotificationService

No Error processing, No LeakyBucket

// Internal configuration:
<INotificationConfig> {
  eventEmitter: new EventEmitter(),
  leakyBucket: new DummyBucketService(),
  processingInterval: 3,
}

Sample with In-Memory storage and ConsoleTransport

ConsoleTransport - demo transport that nothing really send, but only logs all message to console

import {
  ConsoleTransport,
  GeometryProgressionStrategy,
  INotificationPayload,
  INotificationUser,
  IQueueProcessingEvent,
  LeakyBucketService,
  MemoryStorage,
  NotificationQueueManager,
  NotificationService,
  QUEUE_BEFORE_PROCESSING,
} from '@node-notifications/core';
import { randomInt, randomUUID } from 'crypto';

let service: NotificationService;
let queueManager: NotificationQueueManager;

async function main() {
  // Instantiate Notification Service
  service = new NotificationService(
    // In-Memory StorageService (INotificationStorage implementation)
    await new MemoryStorage().initialize(),
    // All necessary ITransport instances for current project
    {
      console: new ConsoleTransport(),
      // ...,
      // alias_xxxx: new TransportXXXX(),
    },
    // optionally change default configuration
    // In addition this configuration can be overridden by ITransport::config (individualy for each transport)
    {
      // ILeakyBucketService
      // For example send max 10 messages for each transports by one try
      leakyBucket: new LeakyBucketService(10),
      // Or max 8 messages for each transports in 15 sec
      // leakyBucket: new LeakyBucketService(8, 15),

      // ResendStrategy with GeometryProgressionResendStrategy
      // Try resend 20 times from 10 sec interval to 3600 sec used geometry progression (denom 2) to calc next "wait" interval
      // Sample: 10, 20, 40, 80, 160, ... 3600, 3600, ... | max to 20 times or success response
      resendStrategy: new GeometryProgressionStrategy(20, 10, 3600),

      // Override processing interval (default: 3 sec)
      processingInterval: 5, // sec
    },
  );

  // Sample Notification subscriber
  service.eventEmitter.on(QUEUE_BEFORE_PROCESSING, (event: IQueueProcessingEvent) => {
    console.info(`before processing ${ event.items.length } at ${ (new Date()).toLocaleTimeString() }:`);
  });

  // Instantiate Notification Queue Manager and start Queue Processing
  queueManager = new NotificationQueueManager(service).start();
  // To stop Queue Processing:
  // queueManager.stop();

  // ...

  // Sample

  // Find recipient (from database or configuration or define manually)
  const recipient: INotificationUser = {
    id: randomInt(1e10),
    name: 'User-01',
    email: '[email protected]',
    phone: '+380001234567',
  };
  // Or for single transport we can use transport specific string
  // As sample for email transport:
  // const recipient = '[email protected] User-01';

  // Payload will be processed by appropriate IDataProvider implementation for specific transport
  // It can be INotificationPayload:
  const payload: INotificationPayload = {
    subject: 'Notification',
    body: 'Hello from Notification System!!',
  };
  // Or a simple message body string:
  // const payload = 'Hello from Notification System!!';

  // Find transport aliases for certain purpose (from database or configuration or define manually)
  // array: ['console', 'smtp', 'alias_xxxx'];
  const transports = ['console'];

  // Sample usage (data: INotification)
  service.send({ recipient, payload, transports }).then();
}