1.1.4 • Published 4 years ago

@unibiz/uplink v1.1.4

Weekly downloads
1
License
UNLICENSED
Repository
bitbucket
Last release
4 years ago

Table of Contents

Uplink

uplink

uplink is meant to interact the base-station service. To understand more about base-station, please go to base-station repository. It mainly consists of three functions, execute, status and store.

execute api

To execute an action, you'll need to provide respective stage, fact and then action, along with parameters if necessary. Following is some sample usage.

import Uplink from '@sigma-infosolutions/uplink';
const {execute} = Uplink('http://optional-host.goes.here', 'optional-uplink-id', 'optional-auth-token');

const payload = {
  ip: '127.0.0.1'
};

execute('dock', 'section', 'command', payload)
      .then((application) => {
        // do something with application
      })
      .catch((err) => {
        // handle error
      });

Above code demonstrates a call to command command of section which is docked at dock. payload is what required by command command. Please take a note that payload is totally optional. Meaning, if the command does not require it you don't need to pass it.

Optional Arguments:

  • host: First argument represents 'endpoint for uplink', if not provided, it will take value from environment variable UPLINK_ENDPOINT
  • uplinkId: Second argument represents 'current' uplink id, if this argument is omitted, then it will load uplink-id from localstorage, if no uplink-id is persisted in localstorage, a new token will be generated and persisted in localstorage.
  • token: Third argument is auth-token, if no token is provided, token will be omitted by base-station while executing a command on Interface's behalf (this may cause 401 when calling secure endpoints)
import Uplink from '@sigma-infosolutions/uplink';
const {execute} = Uplink() ;

execute('lead', 'application', 'save-checkpoint')
      .then(result => {
        // do something with application
      })
      .catch((err) => {
        // handle error
      });

As you might have noticed, the request is identical to the previous one, except no payload is provided.

status api

This api is used to retrieve status, workflow restricts setting status from outside for workflow, the status is set as an effect of executing an action. Status api is very much similar, expect status can be retrieved for different stage, fact or even whole workflow (i.e. with no arguments.) Sample call.

Status can be retrieved on few levels, to understand in detail, say the status for current workflow is

{
    lead: {
      application: {
        id: 'CE-091234',
        applicantId: 'CE-009122342'
      },
      offer: {
        id: 'CE-OF-1123',
        amount: 4000,
        currency: 'INR'
      }
    },
    converted: {
      loan: {
        id: 'CE-99803',
        amount: 49500
      }
    }
}

Section level

import Uplink from '@sigma-infosolutions/uplink';
const {status} = Uplink();

status('lead', 'application')
      .then((application) => {
         /* Application object will be
           {
             id: 'CE-091234',
             applicantId: 'CE-009122342'
           }
         */

      })
      .catch((err) => {
        // handle error
      });

Dock level

import Uplink from '@sigma-infosolutions/uplink';
const {status} = Uplink();

status('lead')
      .then((lead) => {
        /*
           lead object will be
           {
             application: {
               id: 'CE-091234',
               applicantId: 'CE-009122342'
             },
             offer: {
               id: 'CE-OF-1123',
               amount: 4000,
               currency: 'INR'
             }
           }
        */
      })
      .catch((err) => {
        // handle error
      });

Root (base-station) level -- This is not supported as off now (If requirement arises, we may implement this api).

import Uplink from '@sigma-infosolutions/uplink';
const {status} = Uplink();

status()
      .then((root) => {
        /*
           root object will have
           {
               lead: {
                 application: {
                   id: 'CE-091234',
                   applicantId: 'CE-009122342'
                 },
                 offer: {
                   id: 'CE-OF-1123',
                   amount: 4000,
                   currency: 'INR'
                 }
               },
               converted: {
                 loan: {
                   id: 'CE-99803',
                   amount: 49500
                 }
               }
           }
        */
      })
      .catch((err) => {
        // handle error
      });