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

@bpmromandie/notification-service-lib

v1.0.14

Published

The `@bpmromandie/notification-service-lib` is a library for sending notifications via different channels such as email, SMS, and UI. It provides a simple API to integrate notification services into other microservices and comes with built-in support for

Downloads

139

Readme

@bpmromandie/notification-service-lib

The @bpmromandie/notification-service-lib is a library for sending notifications via different channels such as email, SMS, and UI. It provides a simple API to integrate notification services into other microservices and comes with built-in support for checking notification service health.

Features

  • Send notifications through various channels: email, SMS, UI, and queue.
  • Configurable via constructor for flexibility.
  • Supports Axios for making HTTP requests.
  • Easily integrable with different logging solutions.
  • Supports TypeScript with type declarations.

Login, Build, publish and View

To Login

npm login --registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/ --auth-type=web

Build and publish

npm run build
npm publish

To view

npm view @bpmromandie/notification-service-lib --registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/

Installation

You can install the library using npm from our private Artifactory registry (https://bin.swisscom.com/artifactory):

npm install @bpmromandie/notification-service-lib --registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/

Or if you're testing locally and using npm link

npm link notification-service-lib

Or if you using npm pack for local testing

cd ../libs/notification-service-lib
npm pack

Usage

Import the Library

import NotificationService from '@bpmromandie/notification-service-lib';

Sending Notifications

To send a notification, we need to create an instance of notificationService and use the sendNotification method.

const notificationService = new NotificationService({
  baseURL: process.env.API_NOTIFICATION_URL || 'http://localhost:6003',// Fallback to a default URL
  timeout: 10000, // Optional: You can set a custom timeout (default is 5000ms)
});

const notificationContent = {
  subject: 'KYC Rievew',
  body: 'Please verify your account by clicking the link.',
  recipient: '[email protected]',
};

// Sending an email notification
notificationService.sendNotification('email', notificationContent)
  .then(response => {
    console.log('Notification sent successfully:', response);
  })
  .catch(error => {
    console.error('Failed to send notification:', error);
  });

Checking Service Health

To verify if the notification service is running, use the checkNotificationConnection method:

notificationService.checkNotificationConnection()
  .then(isHealthy => {
    if (isHealthy) {
      console.log('Notification service is healthy');
    } else {
      console.log('Notification service is down');
    }
  })
  .catch(error => {
    console.error('Error checking service health:', error);
  });

Configuration

When initializing the NotificationService, you can configure the following options:

  • baseURL (required): The base URL of the notification service (e.g., http://localhost:6003).
  • timeout (optional): The maximum time (in milliseconds) before a request times out. Default is 5000.
const notificationService = new NotificationService({
  baseURL: 'http://localhost:6003',
  timeout: 8000,
});

API - NotificationService

  • Constructor
constructor(config: { baseURL: string; timeout?: number });
  • Methods : sendNotification(channel: string, content: any): Promise

Sends a notification via the specified channel.

  • channel: The notification channel ('email', 'sms', 'ui', 'queue').
  • content: The content of the notification (e.g., subject, body, recipient).

Clean and Install Script

The script used to clean up old dependencies and install both public and private npm packages from specified registries.

  • The script is available for both Linux/macOS (bash: clean-and-install.sh) and Windows (using PowerShell: clean-and-install.ps1).

Features

  • Cleans up node_modules and package-lock.json.
  • Cleans the npm cache.
  • Installs public npm packages from the public npm registry.
  • Installs private npm packages (https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/).
  • Verifies successful installation of private packages.
  • Prompts for user confirmation before starting and logs all actions.
  • Requires the user to press any key to close the script after it finishes, allowing them to review the logs.

Requirements

  • npm: Ensure that npm is installed and available in your system's PATH.
  • Private npm registry: If you're using a private npm registry (https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/), make sure to have the necessary authentication set up (e.g., using .npmrc).

Installation

.npmrc Configuration (Recommended)

For the correct registry settings, add the following to your project's .npmrc file:

# Use the default npm registry for public packages
registry=https://registry.npmjs.org/

# Use the private Artifactory registry for @bpmromandie scope
@bpmromandie:registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/

This ensures that public packages are fetched from the public registry and private packages (under @bpmromandie) are fetched from your Artifactory registry.

Usage Instructions

For Linux/macOS Users (Bash)
  1. Open a terminal.

  2. Navigate to the project directory.

  3. Make sure the script is executable:

    chmod +x clean-and-install.sh
  4. Run the script:

    ./clean-and-install.sh
  5. The script will:

    • Prompt for confirmation to clean and install dependencies.
    • Remove node_modules and package-lock.json.
    • Clean the npm cache.
    • Install public and private packages.
    • Prompt for any key to be pressed before exiting to allow log review.
For Windows Users (PowerShell)
  1. Open a PowerShell.
  2. Navigate to the project directory.
  3. Run the script:
    ./clean-and-install.ps1
  4. The script will:
    • Prompt for confirmation to clean and install dependencies.
    • Remove node_modules and package-lock.json.
    • Clean the npm cache.
    • Install public and private packages.
    • Prompt for any key to be pressed before exiting to allow log review.

Environment Variables

The script uses the following environment variables:

  • PRIVATE_NPM_REGISTRY: The URL of your private npm registry (https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/). You can set it manually in the script if not using .npmrc.

Logs and Output

The script provides detailed logs during execution:

  • [INFO]: General informational messages.
    • [ERROR]: Error messages in case of failures.
      Are you sure you want to clean and install (y/n)? y
      [INFO] Starting clean and install process...
      [INFO] Cleaning up old node_modules and package-lock.json...
      [INFO] Removed node_modules.
      [INFO] Removed package-lock.json.
      [INFO] Cleaning npm cache...
      [INFO] Installing public npm packages from https://registry.npmjs.org/...
      [INFO] Installing private npm packages from https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/...
      [INFO] Installing @bpmromandie/notification-service-lib...
      [INFO] Installing @bpmromandie/kyc_common_types...
      [INFO] All packages installed successfully.
      Press any key to close...
      

Dockerfile.dev - Development Environment

This includes a development Dockerfile (Dockerfile.dev) that sets up a Node.js development environment with nodemon for hot reloading, installs public and private npm packages, and runs your app as a non-root user.

Features

  • Hot Reloading: The development environment includes nodemon for automatic app restarts upon file changes.
  • Private and Public NPM Registry Configuration: Handles both public and private npm packages from your specified registry.
  • Non-Root User: Runs the application using a non-root user for improved security.
  • Environment Variables: Copies environment configuration from .env.default to .env.

Requirements

  • Docker: Ensure that Docker is installed and running on your machine.
  • Private NPM Registry: If your project uses private npm packages (e.g., Artifactory), make sure your .npmrc is correctly configured for authentication.

Setup

1. .npmrc Configuration for Private NPM Registry

If your project uses private npm packages (e.g., @bpmromandie scope), you must configure .npmrc with the correct registry and credentials. Here's an example .npmrc file:

@bpmromandie:registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/
//bin.swisscom.com/artifactory/api/npm/kyc-npm-local/:username=YOUR_USERNAME
//bin.swisscom.com/artifactory/api/npm/kyc-npm-local/:_password=YOUR_BASE64_ENCODED_PASSWORD
//bin.swisscom.com/artifactory/api/npm/kyc-npm-local/:email=YOUR_EMAIL
  • Replace YOUR_USERNAME, YOUR_BASE64_ENCODED_PASSWORD, and YOUR_EMAIL with your actual credentials.
  • Ensure .npmrc is in your project root and will be copied during the Docker build process.

Quick local setup

  • npm config set @bpmromandie:registry https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/
  • npm login --scope=@bpmromandie --registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/
  • npm i
  • modify the package version in package.json
  • npm run build
  • npm publish