<h1 align="center"></h1>

<div align="center">
  <a href="http://nestjs.com/" target="_blank">
    <img src="https://nestjs.com/img/logo_text.svg" width="150" alt="Nest Logo" />
  </a>
</div>

<h3 align="center">Nest-Vault – NestJS wrapper for Hashicorp Vault</h3>

<div align="center">
  <a href="https://nestjs.com" target="_blank">
    <img src="https://img.shields.io/badge/built%20with-NestJs-red.svg" alt="Built with NestJS">
  </a>
  <a href="https://github.com/nestjsplus/dyn-schematics" target="_blank">
    <img src="https://img.shields.io/badge/Built%20with-%40nestjsplus%2Fdyn--schematics-brightgreen" alt="Built with @nestjsplus/dyn-schematics">
  </a>
</div>

This dynamic module was generated with [Nest Dynamic Package Generator Schematics](https://github.com/nestjsplus/dyn-schematics).  You can read more about using the generator [here](https://github.com/nestjsplus/dyn-schematics).

### Installation

To install this generated project:

```bash
npm install nest-vault --save
```

(or yarn equivalent)

### Test

You can test this module if Hashicorp Vault is running locally at http://127.0.0.1:8200/v1 (or you can edit the .env file to change this URL).

```bash
cd ./node_modules/nest-vault
npm run start:dev
```

Then connect to [http://localhost:3000](http://localhost:3000) and you should see the status of your vault.

### Usage

```javascript
@Module({
  imports: [
    ConfigModule.forRoot({}),

    NestVaultModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          baseUrl: configService.get('VAULT_URL'),
        };
      },
    }),
  ],
})
```

Look at `src/nest-vault-client` for more details.

This wrapper is using [hashi-vault-js](https://www.npmjs.com/package/hashi-vault-js) module, so take a look how to use it.

```javascript
@Controller()
export class NestVaultClientController {
  constructor(@Inject(VAULT_CONNECTION) private readonly vault) {}

  @Get()
  async index() {
    return await this.vault.healthCheck();
  }
}
```

Good luck!
