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

express-basistheory-tokenize

v1.0.3

Published

automatically tokenize requests and detokenize responses to avoid dangerous plaintext data touching your code

Downloads

6

Readme

NodeJs Middleware for Tokenizing request/response data

This middleware helpw when you're looking to secure, encrypt, tokenize, or otherwise not lose data you consider senstiive. By including one middleware, express will automatically tokenize (secure your data with BasisTheory) the properties you tell it to. Finally, the middleware will also handle turning the value back into the raw value automatically as well responding with a token.

Installation

Using Node Package Manager

npm install --save express-basistheory-tokenize

Using Yarn

yarn add express-basistheory-tokenize

Documentation

Usage

Get a Basis Theory API Key

  1. Head over to Basis Theory to create an account
  2. Create a new server-to-server Appliation with the following permissions: token:general:create and token:general:read. or click here to pre-fill the Application form
  3. Copy the API Key you create and use it below

Set Basis Theory API Key

You can either set your API Key with an environment variable called BT-API-KEY or you can pass apiKey directly into the middleware. The apiKey passed into the middleware will take presidence over the ENV value.

Example of protecting your data

In this example, we use both the tokenize and detokenize middleware to secure your data on way into your request and then detokenize the response for values you want to be able to display back to your customer. For example, you want to encrypt an emailAddress and then be able to display it back to the user.

Full code can be found here.

import { tokenize, detokenize } from "express-basistheory-tokenize";

const app = express();

app.use(express.json());

// configure which dangerous values to tokenize before calling request code
app.use(
  tokenize({
    tokenize: {
     "apiKey": "<PUT KEY HERE>", 
      "/": ["encrypt_this_value", "keep_this_safe"], // this will tokenize the property encrypt_this_value on the path '/'
    },
  })
);

// configure which token values to detokenize before responding
app.use(
  detokenize({
    detokenize: {
      "apiKey": "<PUT KEY HERE>",
      "/": ["encrypt_this_value"], // this will tokenize the property encrypt_this_value on the path '/'
    },
  })
);

app.post("/", function (req, res) {
  res.send(req.body);
});

app.listen(3000);

Test it out!

curl --location --request POST 'http://localhost:3000' \
--header 'Content-Type: application/json' \
--data-raw '{
    "encrypt_this_value": "dangerous data",
    "dont_encrypt": "not dangerous",
    "encrypt_this_value": "data from customer"
}'

Response:

{ 
    "dont_encrypt":"not dangerous",
    "encrypt_this_value":"data from customer",
    "keep_this_safe":"9f3c21c9-3ebe-4bb3-9665-a6e1d9d8a8a8"
}

🎉 - You can now save the encrypt_this_value and keep_this_safe to your database without worrying about storying the actual dangerous data and can call Basis Theory you need to use it! Check out more about how you can use the data on Basis Theory's documentation.

Test

Run the following command from the root of the project:

yarn test