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

@edirect/encryption-handler

v1.2.0

Published

A simple lib o facilitate interaction with the encryption api

Downloads

7

Readme

Encryption Middleware Library

A library that provides a set of middlewares for decrypting the request body and encrypting the API response.

Getting Started:

  1. Install the package in the chosen service

    npm install @edirect/encryption-handler --save
  2. The environment variables of the service that has installed the package must be updated

    On projects that work with the config package, you should add the following environment variables to the default.json or the .json responsible for the environment variables.

    {
    "encryption-service": {
        "baseUrl": "http://localhost:4212"
    },
    "entity-service": {
        "baseUrl": "http://localhost:9091"
    }
    }

    On projects that work with the .env file, you can simply set the environment variable on the correspondent file.

    ENCRYPTION_URL=<my_encryption_service_dns>
    ENTITY_URL=<my_entity_service_dns>

Usage Examples:

  • Express:
const express = require('express')

/* Require the package by setting a default name or extracting the methods */
const encryptionHandler = require('@edirect/encryption-handler')

const app = express()
const PORT = 3000

/* Set usage of the middlewares (decrypt/encrypt) */
const middleware = [ encryptionHandler.decrypt, encryptionHandler.encrypt ]

/* Addition of middleware array usage on an endpoint */
app.post('/', middleware, (request, response) => handleRequest)
  • NestJs:
/* Require the package by setting a default name or extracting the methods */
import * as encryptionHandler from '@edirect/encryption-handler';

import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { PolicyModule } from './policy/policy.module';
import { PolicyController } from './policy/policy.controller.ts';

@Module({
  imports: [PolicyModule],
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      /* Addition of middleware usage on endpoints separated by comma */
      .apply(encryptionHandler.decrypt, encryptionHandler.encrypt)
      .forRoutes(PolicyController);
  }
}

Development Environment

Aiming to show you how to use and test the package locally, we are going to take the package installation in the gateway as an example.

Clone the encryption-js-lib package project in your local environment

$ git clone [email protected]:gofrank/encryption-js-lib.git

Supposing you have the insurtech-gateway service installed in your environment. Download the package in the gateway service by running one of the following commands:

$ npm install @edirect/encryption-handler --save
$ npm install /your/file/full/path/to/encryption-js-lib

In the root of the encryption-js-lib package run the following command:

$ npm link

In the root of the insurtech-gateway service run the following command:

$ npm link @edirect/encryption-handler

Every change you do on the package is going to be reflected in the package installed in the Gateway service.

Possible Responses:

Using these middlewares the client can receive different types of responses depending on whether the decryption/encryption flow has succeeded or not.

  • Success Response:
{
  "status": 200,
  "data": "encrypted/signed string"
}
  • Error Response
{ "status": 400, "code": "ENC001", "message": "Failed to encrypt" }
{ "status": 400, "code": "DEC001", "message": "Failed to decrypt" }
{ "status": 401, "code": "SIG001", "message": "Invalid signature" }
{ "status": 401, "code": "VAD001", "message": "Missing partner’s or bolttech’s keys" }
{ "status": 500, "code": "SYS001", "message": "System Error" }

Description:

  ENC001: Failed to encrypt due to wrong payload format or internal error
  DEC001: Failed to decrypt due to wrong payload format or internal error
  SIG001: Failed to verify the signature
  VAD001: Missing partner’s or bolttech’s keys
  SYS001: Internal server error

Encryption / Decryption Flow: