Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bpmromandie/notification-service-lib

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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

  • 1.0.13
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@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: 'user@example.com',
};

// 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

Installation

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:

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

FAQs

Package last updated on 16 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc