npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stashbase/node-sdk

v0.5.0

Published

Stashbase Node SDK

Readme

Stashbase Node SDK

The official SDK for Stashbase, a secrets management platform for developers.

Features:

  • Manage projects, environments, and secrets from Node.js
  • Inject secrets into your process environment
  • Simple, promise-based API
  • Zero non-development dependencies (security-focused runtime footprint)
  • And more...

Table of Contents

Installation

Install with npm or npm compatible package manager (bun, pnpm, etc.). We recommend using bun for the best experience.

Supported runtime: Node.js 18+.

npm install @stashbase/node-sdk

Usage

For full documentation, please visit Stashbase Node SDK.

Here are some common usage examples for the Stashbase Node SDK:

Secret values are validated by UTF-8 byte length. Maximum secret value size: 16 KB.

Auto client

Use createClient to create a client with explicit scope selection.

import { createClient } from '@stashbase/node-sdk'

const client = createClient({
  apiKey: process.env.STASHBASE_API_KEY,
  scope: 'workspace', // or "environment"
  timeoutMs: 5000, // optional, hard capped at 10000
  retries: 3, // optional, hard capped at 10
  hooks: {
    beforeRequest: ({ method, url }) => console.log('[request]', method, url),
    afterResponse: ({ response }) => console.log('[response]', response.status),
    onError: ({ error }) => console.error('[error]', error),
  }, // optional
})
console.log(client.scope) // "workspace" or "environment"

Workspace client

Use workspace client to manage resources in a workspace, you can use Service Account or Personal API key.

import { createWorkspaceClient } from '@stashbase/node-sdk'

const client = createWorkspaceClient(process.env.STASHBASE_API_KEY)
console.log(client.scope) // "workspace"
const client = createWorkspaceClient(process.env.STASHBASE_API_KEY, {
  timeoutMs: 5000, // optional, hard capped at 10000
  retries: 3, // optional, hard capped at 10
  hooks: {
    beforeRequest: ({ method, url }) => console.log('[request]', method, url),
  }, // optional
})

List project

const { data, error } = await client.projects.list()

Create environment

const { data, error } = await client.environments({ project: 'project-name' }).create({
  name: 'api-dev',
  isProduction: false,
})

Bind workspace context

const ctx = client.withContext({
  project: 'project-name',
  environment: 'dev',
})

const { data, error } = await ctx.secrets.list()

Get workspace secret metadata

const ctx = client.withContext({
  project: 'project-name',
  environment: 'dev',
})

const { data, error } = await ctx.secrets.getMetadata('HOST')

List workspace secrets metadata

const ctx = client.withContext({
  project: 'project-name',
  environment: 'dev',
})

const { data, error } = await ctx.secrets.listMetadata()

Load environment

This method will load the environment and inject the secrets into the process.

// using workspace client
const { error } = await client.environments({ project: 'project-name' }).load('api-dev')

Environment client

Use environment client to manage resources in a specific environment, using Environment Account API key.

import { createEnvironmentClient } from '@stashbase/node-sdk'

const client = createEnvironmentClient(process.env.STASHBASE_ENV_API_KEY)
console.log(client.scope) // "environment"
const client = createEnvironmentClient(process.env.STASHBASE_ENV_API_KEY, {
  timeoutMs: 5000, // optional, hard capped at 10000
  retries: 3, // optional, hard capped at 10
  hooks: {
    beforeRequest: ({ method, url }) => console.log('[request]', method, url),
  }, // optional
})

Timeouts and retries

  • Default request timeout is 5000 ms.
  • Maximum request timeout is 10000 ms.
  • Default retry count is 3.
  • Maximum retry count is 10.
  • timeoutMs is applied per request attempt, not as a total wall-clock budget across all retries.

The transport defaults are also exported from the package root:

import {
  DEFAULT_API_TIMEOUT_MS,
  MAX_API_TIMEOUT_MS,
  DEFAULT_API_RETRIES,
  MAX_API_RETRIES,
} from '@stashbase/node-sdk'

Transport hooks

Hooks can be configured at creation time and updated later at runtime through client.options.hooks.

const client = createWorkspaceClient(process.env.STASHBASE_API_KEY)

client.options.hooks = {
  beforeRequest: ({ method, url }) => console.log('[request]', method, url),
  afterResponse: ({ response }) => console.log('[response]', response.status),
  onError: ({ error }) => console.error('[error]', error),
}

Hook behavior contract:

  • beforeRequest: runs before each request attempt.
  • afterResponse: runs after receiving a response (including non-2xx).
  • onError: runs when request processing throws.
  • If beforeRequest or afterResponse throws, request fails with HookExecutionError in response.error.
  • If onError throws, that error is ignored and the original request error is preserved.

Error handling

Every SDK method returns an ApiResponse shape:

const response = await client.projects.get('project-name')

if (!response.ok) {
  console.error(response.error.code, response.error.message, response.status)
  return
}

console.log(response.data)

You can also branch on stable error codes:

const response = await client.projects.get('project-name')

if (!response.ok) {
  switch (response.error.code) {
    case 'resource.project_not_found':
      console.log('Project does not exist')
      break
    case 'auth.unauthorized':
      console.log('API key is invalid or missing permissions')
      break
    default:
      console.log(response.error.message)
  }
}

Get environment details

const { data, error } = await client.environment.get()

Load environment

This method will load the environment and inject the secrets into the process.

const { error } = await client.environment.load()

List secrets

const { data, error } = await client.secrets.list()

Get environment secret metadata

const { data, error } = await client.secrets.getMetadata('HOST')

List environment secrets metadata

const { data, error } = await client.secrets.listMetadata()

Type imports

All public SDK types are exported from the package root.

import type { Secret, ListSecretsResponse, GenericApiErrorCode, SecretErrors } from '@stashbase/node-sdk'

Contributing

Bug fixes, documentation improvements, and library improvements are always welcome.

See CONTRIBUTING.md for details.

License

Stashbase Node SDK is licensed under the MIT License. You can find the license in the LICENSE.txt file.