0.1.1 • Published 7 years ago

tv-js-sdk v0.1.1

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
7 years ago

TrueVault JavaScript SDK

The official JavasScript SDK for TrueVault. For more information about TrueVault, check out our website and API documentation. To see how the SDK is used in a real application, check out the TrueVault React Sample App.

Note: This SDK is only supported for the latest release of Chrome.

Install using unpkg CDN

Simply copy this line into your HTML:

<script src="https://unpkg.com/tv-js-sdk@0.1.0/build/index.js"></script>

Install using yarn / npm

First download the package using yarn or npm.

yarn add tv-js-sdk

// OR

npm install tv-js-sdk

Then import the JS SDK into your project:

ES6

import TrueVaultClient from 'tv-js-sdk';

ES5

const TrueVaultClient = require('tv-js-sdk');

Usage

Initialize a TrueVaultClient using an access token or API key

const tvClient = new TrueVaultClient(apiKeyOrAccessToken);

You can also create a new TrueVaultClient by logging in:

const tvClient = await TrueVaultClient.login(accountId, username, password, mfaCode);

Asynchronous Requests

The methods in this SDK make asynchronous web requests to TrueVault and return Promises. We recommend using async/await in favor of Promises wherever possible for clarity and conciseness.

async/await

async readTrueVaultDocument() {
    try {
        const response = await tvClient.readDocument(vaultId, documentId);
        console.log(response);
    } catch (err) {
        console.error(err);
    }
}

Promises

readTrueVaultDocument() {
    tvClient.readDocument(vaultId, documentId).then(response => {
        console.log(response);
    }).catch(err => {
        console.error(err);
    });
}

Example

Test out the SDK with this simple JSFiddle example.

Development

Make changes to index.js and then bundle them into build/index.js with webpack:

./node_modules/.bin/webpack

License

This SDK is released under the BSD 3-Clause License.