TrueVault JavaScript SDK
The official JavaScript 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. You can also browse the documentation for this SDK.
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/truevault/build/index.js"></script>
Install using yarn / npm
First download the package using yarn or npm.
yarn add truevault
// OR
npm install truevault
Then import the JS SDK into your project:
ES6
import TrueVaultClient from 'truevault';
ES5
const TrueVaultClient = require('truevault');
Usage
Initialize a TrueVaultClient using an access token or API key:
const tvClient = new TrueVaultClient({apiKey: 'your api key'});
You can also create a new TrueVaultClient by logging in:
const tvClient = await TrueVaultClient.login(accountId, username, password, mfaCode);
See the documentation for more info.
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:
yarn webpack
Documentation
This project uses documentationjs. To generate the docs:
rm -rf docs && yarn documentation -- build index.js -f html -o docs
The documentation is available via GitHub Pages.
License
This SDK is released under the BSD 3-Clause License.
Releasing a new version
- Rebuild
build/index.js
; see above - Rebuild documentation; see above
- Update version in
package.json
- Commit
npm publish
- Tag