@grow-codes/hashicorp-vault - v0.1.1
    Preparing search index...

    Class VaultClient

    Client for HashiCorp Vault.

    const client = VaultClient.fromEnv();          // VAULT_ADDR / VAULT_TOKEN / GROW_HASHICORP_VAULT_*
    await client.kv().write("app/db", { password: "s3cret" });
    const secret = await client.kv().read("app/db");
    await client.close();
    Index
    auth: AuthApi

    Logins, token self-service and token renewal.

    config: VaultConfig

    The immutable configuration.

    leases: LeaseManager

    Lease renew/revoke/lookup and automatic lease renewal.

    sys: Sys

    System backend (health, seal status, policies, mounts, auth methods, AppRole admin).

    wrapping: Wrapping

    Response wrapping.

    • get namespace(): string | undefined

      The namespace sent as X-Vault-Namespace, or undefined for the root namespace.

      Returns string | undefined

    • Stops token renewers, managed leases and secret watchers, then releases connections. Idempotent.

      Returns Promise<void>

    • Unauthenticated health: GET /v1/sys/health (answers 200 in every node state). healthy is true only for an active, unsealed node; status is active, standby, perfstandby, sealed or uninitialized (unreachable on any error). details holds version, initialized, sealed, standby and clusterName (when set); on errors error (and httpStatus). Never throws except for CANCELLED and CONFIG.

      Parameters

      Returns Promise<HealthStatus>

    • KV mount with auto-detected version (default mount config.kvMount). The same instance is returned for the same mount.

      Parameters

      • mount: string = ...

      Returns KvMount

    • KV version 1 mount (no detection).

      Parameters

      • mount: string = ...

      Returns KvV1

    • KV version 2 mount (no detection).

      Parameters

      • mount: string = ...

      Returns KvV2

    • Authenticated round trip (GET /v1/auth/token/lookup-self, allowed for every valid token). Returns the latency in ms; a missing, invalid or revoked token raises AuthenticationError.

      Parameters

      Returns Promise<number>

    • PKI engine (default mount pki).

      Parameters

      • mount: string = "pki"

      Returns Pki

    • Calls any Vault API path (/v1/<path>) with the client token, namespace, retries and error mapping. Use it for endpoints this SDK has no method for.

      Type Parameters

      • T = Record<string, unknown>

      Parameters

      • method: "GET" | "PUT" | "DELETE" | "POST" | "PATCH"
      • path: string
      • options: RawRequestOptions = {}

      Returns Promise<RawResponse<T>>

    • Replaces the client token (undefined removes it). A withNamespace view starts with its parent's token but owns it afterwards: the change affects only this client.

      Parameters

      • token: string | Secret | undefined

      Returns void

    • Transit engine (default mount transit).

      Parameters

      • mount: string = "transit"

      Returns Transit

    • A client view that sends X-Vault-Namespace: <namespace> on every request (an empty string selects the root namespace: no header). The view shares the connection pool and starts with this client's current token; after that, logins and token changes of the view and of this client are independent. Surrounding whitespace and slashes are removed; a namespace that still contains whitespace throws ConfigError. Closing the view stops only its own renewers, leases and watchers; closing this client also closes its views.

      Vault Enterprise only. Vault OSS ignores the header and serves the root namespace, so a wrong namespace is not detected there.

      const team = client.withNamespace("team-a");
      await team.kv().read("app/db"); // X-Vault-Namespace: team-a

      Parameters

      • namespace: string

      Returns VaultClient