DefinitelyTyped/types/node-vault/node-vault-tests.ts
Eric Heikes 4820191c9e Rewrite module function declaration & export to match template
Follows template in TS docs now:
https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html

Also makes it possible to reference interfaces from the NodeVault
namespace outside of this module.
2018-02-15 10:27:14 -08:00

29 lines
912 B
TypeScript

import nv = require("node-vault");
// Test code came from the sample code in README of the module.
const options: nv.VaultOptions = {
apiVersion: 'v1', // default
endpoint: 'http://127.0.0.1:8200', // default
token: '1234', // optional client token; can be fetched after valid initialization of the server
};
// get new instance of the client
const vault = nv(options);
// init vault server
vault.init({ secret_shares: 1, secret_threshold: 1 })
.then((result) => {
const keys = result.keys;
// set token for all following requests
vault.token = result.root_token;
// unseal vault server
return vault.unseal({ secret_shares: 1, key: keys[0] });
})
.catch(console.error);
// write, read and delete secrets
vault.write('secret/hello', { value: 'world', lease: '1s' })
.then(() => vault.read('secret/hello'))
.then(() => vault.delete('secret/hello'))
.catch(console.error);