node-vault
A Javascript client for the HTTP API of HashiCorp's vault with a focus on ease of use.
npm install @litehex/node-vault
Usage
Init and unseal vault
import { Client } from '@litehex/node-vault';
const vc = new Client({
apiVersion: 'v1',
endpoint: 'http://127.0.0.1:8200',
token: 'hv.xxxxxxxxxxxxxxxxxxxxx'
});
vc.init({ secret_shares: 1, secret_threshold: 1 }).then((res) => {
const { keys, root_token } = res;
vc.token = root_token;
vc.unseal({ secret_shares: 1, key: keys[0] });
});
Write, read and delete secrets
vc.write({ path: 'secret/hello', data: { foo: 'bar' } }).then(async () => {
const data = await vc.read({ path: 'secret/hello' });
console.log(data);
await vc.delete({ path: 'secret/hello' });
});
Docs
Examples
Custom command implementation
import { generateCommand } from '@litehex/node-vault';
import { z } from 'zod';
const status = generateCommand({
path: '/sys/seal-status',
method: 'GET',
client: vc,
refine: (req) => {
req.headers['X-Custom-Header'] = 'value';
return req;
},
schema: {
response: z.any()
}
});
status().then((res) => {
console.log(res);
});
Using a proxy or having the ability to modify the outgoing request.
import { Client } from '@litehex/node-vault';
import { ProxyAgent } from 'undici';
const agent = new ProxyAgent('http://localhost:8080');
const vc = new Client({
request: {
dispatcher: agent,
headers: {
'X-Custom-Header': 'value'
}
}
});
Credits
This project is inspired by kr1sp1n/node-vault, and thanks to the contributors for their efforts.
License
This project is licensed under the GPLv3 License - see the LICENSE file for details