Sample Plugin Code

BioT provides a sample JavaScript Plugin code that describes the steps needed in plugin development.
The code is available free under the MIT license and can be browsed here.

Prerequisites

To pack and deploy the sample, you need Node.js installed on your computer.
You can download it for free from here.

Download the Code

To download the code, make sure you have GIT installed and execute the following command from our command line:

git clone https://bitbucket.org/softimize/notifications-handler-lambda-seed.git

To download dependencies, execute the following command line:
npm install

Basic Plugin Flow

The following boilerplate functions should be executed before the code can be executed:
(You may change them as required)

  • extractDataFromEvent - Extracts the data and metadata from the event.
  • getTraceId - Get a trace ID from the event (or fallback to a trace ID from a BioT service). The trace ID is used for better logging traceability.
  • configureLogger - Create new logs format (including a traceId).
  • authenticate - Authenticate the token sent by the notification service.
  • login - Login to BioT (using a service user) and get a token.
  • callToAPIExample - An example of calling a BioT service.
  • response - Send response (see errorResponseCreator for error responses).

extractDataFromEvent

A helper function that obtains the raw JSON data from the event.

getTraceId

The trace ID is a unique ID string that will be set in the header of each API call and saved to the log. Using this unique ID will allow us to trace the whole flow of the call, in case of a problem, beginning with the plugin and going through all the API calls that the plugin made, and any internal API calls made by the platform until the plugin response.

configureLogger

This function prepares the log structure for a well-structured log that will enable easy searching when needed.

authenticate

This function validates the JWT token received from BioT to ensure the call originated from there and not from any unauthorized origin.

login

Before making an API call to BioT the plugin needs to obtain a new JWT token using the service user credentials.

callToAPIExample

This is an example stub code to be replaced with your business logic.

response

The response depends on the plugin and should be updated according to your business logic.

Deploy the Plugin

You may want to zip the source code before deploying it by executing the following command:
npm run zip

To deploy the code, refer to Custom Plugin Deployment.

Set Environment Variables

The following environment variables need to be set before the plugin can be executed:

Variable Name

Description

APP_NAME

Name of this Plugin, used for logging purposes.

BASE_URL

The base API URL of your BioT account.
For example, https://api.dev.biot-med.com

JWT_PERMISSION

Set as ACTION_NOTIFICATION

BIOT_PUBLIC_KEY

The public key of BioT, used to ensure the call originated from BioT. The key can be obtained by making a request to:
GET: https://<your_biot_domain>/ums/v1/security/public-key

SERVICE_USER_ID

The service user ID.
See Creating a Service User for Your Plugin.

SERVICE_USER_SECRET_KEY

The service user secret key.
See Creating a Service User for Your Plugin.

To set these environment variables, login to the AWS console and go to the Lambda service.
From the list, select your Lambda function and click on "Configuration", then "Environment Variables" and finally "Edit".

15221522

In the Edit Environment Variables box that appears, enter the environment variables as keys and values. To add more than one environment variable, click Add environment variable. When finished, click Save.

13471347

Test Your Plugin

Now register your Plugin as a Notification or Interceptor and verify that it works.


Did this page help you?