0.8.0-alpha.5 • Published 2 years ago

@mercadoni/elementals v0.8.0-alpha.5

Weekly downloads
310
License
MIT
Repository
github
Last release
2 years ago

Elementals

Building blocks for NodeJS services

  1. Logger
  2. Cryptic

Logger

Mask data

To mask sensitive information each method (debug, error, info) receives maskedFields:

logger.info(message, data, maskedFields)

maskedFields is a list of name fields to be masked, it's possible to mask nested JSON by using the field.subfield notation.

Examples

  • Plain (Depth 0)

    const maskedFields = ['client']
    logger.info('Incoming request', {base: 'POST /jobs/', client:'<test>', body:... }, maskedFields)

    Result

    {
        "message": "Incoming request,
        "data": {
            "base": "POST /jobs/",
            "client": "*****",
            "body": {
                ...
            }
        }
    }
  • Nested Fields

    Example data request:

    data = {
          baseUrl: 'POST /jobs/',
          client: '<test>',
          body: {
            client_reference: '<ref_test>',
            origin: {
              name: 'Store',
              ...
            }
          }
    • Depth 1

      const maskedFields = ['body.origin']
      logger.info('Incoming request', data, maskedFields)

      Result

      {
          "message": "Incoming request,
          "data": {
              "base": "POST /jobs/",
              "client": "<test>",
              "body": {
                  "client_reference": "<ref_test>",
                  "origin": "*******"
                  ...
              }
          }
      }
    • Depth 2

      const maskedFields = ['body.origin.name']
      logger.info('Incoming request', data, maskedFields)

      Result

      {
          "message": "Incoming request,
          "data": {
              "base": "POST /jobs/",
              "client": "<test>",
              "body": {
                  "client_reference": "<ref_test>",
                  "origin":{
                    "name": "*****",
                  }
                  ...
              }
          }
      }

Cryptic

This service can encrypt and decrypt data using any algorithm available in openssl list -cipher-algorithms, for this purpose is necessary to define a key accordingly with the algorithm chosen, in case of using aes-256-cbc the key used in the examples has a length of 32 bytes.

Encrypt

import { encrypt, Algorithm } from '...'
const plaintext = 'h1dd3n_message'
const key = 'Y0ur4p1tokenpr0v1d3dby_123d4g34p'
const crypticResponse = encrypt(Algorithm.AES_256, key, plaintext)

The response is a CrypticResponse object that consists of the iv and the encryptedData both are necessary to decrypt the message. It's possible to receive a Base64 string of the CrypticResponse object by setting encode param to true.

import { encrypt, Algorithm } from '...'
const plaintext = 'h1dd3n_message'
const key = 'Y0ur4p1tokenpr0v1d3dby_123d4g34p'
const crypticResponse = encrypt(Algorithm.AES_256, key, plaintext, true)
// crypticResponse = 'ewoic2VsYXMiOiAiY3JleWVyb24iCn0='

Decrypt

import { decrypt, Algorithm } from '...'
const key = 'Y0ur4p1tokenpr0v1d3dby_123d4g34p'
const decryptedMessage = decrypt(Algorithm.AES_256, key, crypticResponse)

To decrypt a encoded crypticResponse, it's necessary to set encoded param to true.

import { decrypt, Algorithm } from '...'
const key = 'Y0ur4p1tokenpr0v1d3dby_123d4g34p'
const crypticResponse = 'ewoic2VsYXMiOiAiY3JleWVyb24iCn0='
const decryptedMessage = decrypt(Algorithm.AES_256, key, crypticResponse, true)

Bulk Encryption/Decryption

It's possible to encrypt/decrypt a list of objects generating a pair of {iv, encryptedData} for each one, so they can be decrypted individually latter on. First, you have to define the algorithm and key to be used for the bulk operations.

import cryptic, { Algorithm } from '...'
const key = 'Y0ur4p1tokenpr0v1d3dby_123d4g34p'
const cryptic = cryptic(Algorithm.AES_256, key)

Then each encrypt/decrypt function call will only need the values to be encrypted/decrypted.

const objects = [...]
const crypticResponses = cryptic.BulkEncrypt(objects)
const decryptedObjects = cryptic.BulkDecrypt(crypticResponses)

It's possible to receive a list of Base64 strings of the CrypticResponse objects by setting encode param to true.

const crypticResponses = cryptic.BulkEncrypt(objects, true)
// crypticResponses = ['ewoic2VsYXMiOiAiY3JleWVyb24iCn0=', ...]

To decrypt a list of encoded crypticResponses, it's necessary to set encoded param to true.

const decryptedObjects = cryptic.BulkDecrypt(crypticResponses, true)
0.8.0-alpha.5

2 years ago

0.8.0-alpha.4

2 years ago

0.8.0-alpha.3

2 years ago

0.7.8

3 years ago

0.8.0-alpha.2

3 years ago

0.8.0-alpha.1

3 years ago

0.7.7

3 years ago

0.7.7-alpha.10

4 years ago

0.7.7-alpha.9

4 years ago

0.7.7-alpha.8

4 years ago

0.7.7-alpha.7

4 years ago

0.7.7-alpha.6

4 years ago

0.7.7-alpha.5

4 years ago

0.7.7-alpha.4

4 years ago

0.7.7-alpha.3

4 years ago

0.7.7-alpha.2

4 years ago

0.7.7-alpha.1

4 years ago

0.7.7-alpha.0

4 years ago

0.7.6

4 years ago

0.6.22

4 years ago

0.7.5

5 years ago

0.6.21

5 years ago

0.7.4

5 years ago

0.6.20

5 years ago

0.7.3

5 years ago

0.7.3-alpha.1

5 years ago

0.6.19

5 years ago

0.6.18

5 years ago

0.6.17

5 years ago

0.7.3-alpha.0

5 years ago

0.6.16

5 years ago

0.7.0-alpha.8

5 years ago

0.6.15

5 years ago

0.7.0-alpha.7

5 years ago

0.6.14

5 years ago

0.7.0-alpha.6

5 years ago

0.6.13

5 years ago

0.7.0-alpha.5

5 years ago

0.6.12

5 years ago

0.7.0-alpha.4

5 years ago

0.6.11

5 years ago

0.7.0-alpha.3

5 years ago

0.7.0-alpha.2

5 years ago

0.7.0-alpha.1

5 years ago

0.7.0-alpha.0

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.5-alpha.1

5 years ago

0.6.4

6 years ago

0.6.3

6 years ago

0.6.2

6 years ago

0.6.1

6 years ago

0.6.0-alpha.8

6 years ago

0.6.0-alpha.7

6 years ago

0.6.0-alpha.6

6 years ago

0.6.0-alpha.5

6 years ago

0.6.0-alpha.4

6 years ago

0.6.0-alpha.3

6 years ago

0.6.0-alpha.2

6 years ago

0.6.0

6 years ago

0.6.0-alpha.1

6 years ago