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

vnlp-sdk

v1.3.1

Published

VNLP's API SDK

Downloads

385

Readme

Project Overview - VNLP base sdk

Introduction

This project is a utility library designed to provide a collection of helpers for encryption, logging, API communication, and base models, aimed at improving productivity and maintainability in modern software systems. It includes commonly needed tools such as encryption helpers, logging services, and base repository models for database interactions.

Key Features

  • Encryption & Security: RSA and AES encryption helpers to secure data transmission.
  • Base Models & Repositories: Base classes for database models and repositories to interact with your data layer.
  • Logging: Centralized logging utilities to handle logs across various platforms.
  • API Middleware: Middleware for logging Axios requests and responses.

Modules

Core Modules

  • Crypto: Encryption helpers for securing data.
    • RSAEncryption: RSA encryption utility.
    • AESEncryption: AES encryption utility.
  • Base: Base repository and model for interacting with databases.
    • BaseRepository: Provides basic repository functionality.
    • BaseModel: Base class for models, designed for database interactions.
  • Logger: Centralized logging system.
    • Logs all interactions and events across different services.
  • Axios Middleware: Middleware for Axios that logs HTTP request and response data.

TODO

Upcoming Features

  • AWS S3 Helper: Integration with AWS S3 for file uploads and management.
  • Additional Encryption Methods: Including more encryption algorithms such as HMAC, DES, or others.
  • Extended Middleware: Additional middleware for other popular HTTP clients.
  • Advanced Logging Features: Support for more log destinations (e.g., file system, cloud storage) and enhanced log formatting.
  • Database Enhancements: More advanced database helpers for interacting with different databases (e.g., PostgreSQL, MySQL).
  • Email Service: Integration with an email service for sending notifications and alerts.
  • Caching Mechanisms: Adding cache utilities to improve performance with Redis or other caching services.

Installation

To install the package, run the following command:

npm install vnlp-sdk

VNLP logger

Overview

This package provides a centralized logging system designed for use in Node.js applications. It integrates with various logging platforms such as Telegram and supports logging HTTP request and response data. The package uses winston for logging and provides functionality to store logs locally or send them to external channels such as Telegram.

Features

  • Supports logging to the console and file system with rotation.
  • Provides middleware for logging HTTP requests and responses in Express.
  • Integration with Telegram for sending log messages externally.
  • Support for custom error handling and masking sensitive data in logs.
  • Automatically generates unique request IDs for HTTP requests.

Usage

Logger Setup To initialize the logger, use the VNLPLogger class and provide the necessary configuration:

import { VNLPLogger } from 'vnlp-sdk';

const logger = new VNLPLogger({
  serviceName: 'my-service',
  env: 'prod',
  writeFile: true,
  external: {
    isDisabled: false,
    provider: 'telegram',
    botToken: 'your-bot-token',
    channel: 'your-telegram-channel',
  },
});

HTTP Logger Middleware

Use the createHttpLoggerMiddleware function to log HTTP request and response data in an Express.js application:

import { createHttpLoggerMiddleware } from 'vnlp-sdk';
import express from 'express';

const app = express();

app.use(createHttpLoggerMiddleware(logger));

app.get('/', (req, res) => {
  res.send('Hello World');
});

Logging Messages

You can log messages at different levels using the VNLPLogger instance:

logger.info('Informational message', { userId: 123 });
logger.error('Error message', { errorDetails: 'Detailed error info' });
logger.warn('Warning message', { warningDetails: 'Warning details' });

External Logging (Telegram)

Send logs to an external service like Telegram:

logger.logExternal({
  message: 'An external log message',
  level: 'error',
  channel: 'my-telegram-channel',
});

Configuration

VNLPLoggerService

The VNLPLogger requires a configuration object with the following fields:

serviceName: The name of the service to be logged (e.g., my-service). env: The environment the service is running in (e.g., prod, dev, staging). writeFile: Boolean flag to enable or disable file logging. external: Configuration for external logging providers like Telegram. isDisabled: Disable external logging if set to true. provider: The external provider, currently only supports telegram. botToken: Telegram bot token for sending messages. channel: Telegram channel where logs will be sent. envBlackList: List of environments to exclude from external logging (optional). File Logging Logs can be written to files with rotation using winston's DailyRotateFile transport. Logs are stored in the ./logs directory and will be rotated based on the configured pattern.

Masking Sensitive Data Sensitive data such as tokens, authorization headers, and cookies are automatically masked in the logs to prevent leaking sensitive information. You can customize the masking logic as needed.

Contribution

If you'd like to contribute to this project, please fork the repository, make your changes, and submit a pull request. Make sure to write tests for any new features or bug fixes.

License

This project is licensed under the MIT License.