1.0.1 • Published 8 years ago

orchestration-commons-js v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
8 years ago

README

This document explains how to use the library.

Installation

npm install orchestration-commons-js

Usage

First, you need to import the package into your code:

oc = require('orchestration-commons-js');

...

Then, follow these instructions for each function:

checkHeader(headers, headerName)

This function allows you to check if there's a determined header in an Object of headers.

Parameters:

  • headers: Object where the keys are the headers' names and the values are the headers' values.
  • headerName: Name of the header to be looked for.

Examples:

  >> oc.checkHeader({'Test-Header': "abc"},  'Test-Header')
  >> true
                
  >> oc.checkHeader({}, 'Test-Header')
  >> false

checkUserDataHeader(headers)

This function allows you to check if the 'User-Data' header is present.

Parameters:

  • headers: Object where the keys are the headers' names and the values are the headers' values.

Examples:

>> oc.checkUserDataHeader({'User-Data': "abc"})
>> true

>> oc.checkUserDataHeader({})
>> false

decodeUserData(headers)

This function allows you to extract the user data contained in the User-Data header.

Parameters:

  • headers: Object where the keys are the headers' names and the values are the headers' values.

Returns an Object with fields userId, profileId and roles.

Examples:

# Let's assume request has the following content in User-Data: MTIzNDU2Ojo3ODkwMTI6OmFkbWluLS0+d3JpdGU7O3JlYWQvL2ludmVzdG9yLS0+YnV5 

>> decodeUserData({'User-Data': "e3VzZXJJZDogImFiYzEyMyIsIHByb2ZpbGVJZDogImRlZjQ1NiIsIHJvbGVzOiB7YWRtaW46IFsid3JpdGUiLCAicmVhZCJdLCBpbnZlc3RvcjogWyJpbnZlc3QiLCAicGF5Il19fQ=="})

>> {userId: "abc123", profileId: "def456", roles: {admin: ["write", "read"], investor: ["invest", "pay"]}}