# @commander-lol/vault-client

> A pluggable convenience wrapper around the Hashicorp Vault HTTP API

Latest version **0.1.1** (published 2021-02-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @commander-lol/vault-client
pnpm add @commander-lol/vault-client
yarn add @commander-lol/vault-client
bun add @commander-lol/vault-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2021-02-22 |
| First published | 2021-02-22 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Louis Capitanchik |
| Maintainers | commander-lol |
| Keywords | vault, client, wrapper, hashicorp, http-client, JWT |

## Links

- npm: https://www.npmjs.com/package/@commander-lol/vault-client
- npm.io page: https://npm.io/package/@commander-lol/vault-client

## Dependencies (2)

- [date-fns](https://npm.io/package/date-fns.md) ^2.17.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2021-02-22
- 0.1.0 — 2021-02-22

## README

# vault-client

## A pluggable wrapper around the [Hashicorp Vault](https://www.vaultproject.io/) HTTP API

### Installation

` npm install @commander-lol/vault-client`

### What

This library provides the `VaultClient` class, which encapsulates 
1 auth method and 0 or more named stores. Construction overhead amounts
to a few class instantiations with no long-lived resource allocations, so
creating a `VaultClient` per HTTP request is ok (e.g. for short lease JWT based 
auth against the Vault instance with a client token)

### How

```js
const { VaultClient, VaultSimpleAuth, VaultKVStore } = require('@commander-lol/vault-client')

const client = new VaultClient('https://vault.host.example.com', {
    auth: VaultSimpleAuth,
    stores: {
        kv: VaultKVStore,
    },
    options: {
        auth: {
            path: '/v1/auth/approle/login',
            credentials: {
                role_id: '...',
                secret_id: '...',
            },
        },
        kv: {
            path: '/v1/some/path'
        }
    }
})

const value = await client.stores.kv.read('some_key')
```

### More

#### Use JWT auth from Koa request context

_NB: In real world use cases, you should create a utility function
elsewhere for creating a configured client, to keep your route handlers tidy._

```js
const { VaultClient, VaultSimpleAuth, VaultKVStore } = require('@commander-lol/vault-client')

/* ... */

router.get('/secrets/:id', async ctx  => {
    const getCredentials = async () => {
        let header = ctx.get('Authorization')
        if (header.startsWith('Bearer ')) {
            header = header.substr(7)
        }
        
        const values = await someDecodeFn(header)
        
        return {
            jwt: header,
            role: values.role,
        }
    }
    
    const client = new VaultClient('https://vault.example.com', {
        auth: VaultSimpleAuth,
        stores: {
            secrets: VaultKVStore,
        },
        options: {
            auth: {
                path: '/v1/auth/jwt/login',
                credentials: getCredentials,
            },
            secrets: {
                path: '/v1/kvpath',
            },
        },
    })
    
    ctx.body = await client.stores.secrets.read(ctx.params.id)
})

/* ... */

```

---
_Source: https://npm.io/package/@commander-lol/vault-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
