JS SDK

This guide shows how to setup Onboardbase with our JS SDK

Installation

npm install @onboardbase/secrets

or

yarn add @onboardbase/secrets

Setup

Generate .onboardbase.yaml

If you don't have Onboardbase setup file .onboardbase.yaml, go to your project page on Onboardbase, click on the Env dropdown and click to copy the setup for the project to your clipboard.

Then, create a new file in the root of your project named .onboardbase.yaml and paste the content you copied earlier.

If you have Onboardbase CLI, run the below command and follow the instruction to generate a setup file:

cd path/to/project
onboardbase setup

Your final setup file should look like this:

setup:
  project: "test-project"
  environment: "development"

Create an API Key

To create a new API Key, go to your account settings page, and click on your organization's tab, you would find the API Key sections.

On the API Key section, click on Create API Key, Enter an identifying name and a secure passcode string - you can't view this anymore, make it a memorable string.

Once an API Key is generated, click on the options dropdown of the key and then click on copy to copy the newly generated key to your clipboard.

1288

Final setup

In your project .onboardbase.yaml setup file, add two new fields api_key and passcode. Paste the copied API Key from above as the value for the api_key field and enter your memorable encryption passcode.

api_key: "****ANCAME3CFKJG******"
passcode: "TEST_PASSCODE"
setup:
  project: "test-project"
  environment: "development"

Integrate Onboardbase JS SDK

After having API Key and passcode integrated into your setup file.

Import Onboardbase SDK into your project

const { Secrets } = require("@onboardbase/secrets");

Initialize the library in an IIFE, which would ensure secrets are available before they are accessed.

(async () => {
  const secrets = await Secrets.init();
  //  console.log('get secrets', secrets.get()); -> logs all the secrets from onboardbase
})();

And access individual secrets using process.env.SECRET_NAME

console.log(process.env.TEST_SECRET); // -> Secret from onboardbase

Inbuilt SDK Feature

Secure fallback cache

The JavaScript SDK supports caching your secrets to a secured location on the current computer. This cache is useful in case there is an issue with communicating with Onboardbase servers to serve secrets.