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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@agent-base/secret-client

v0.17.0

Published

A TypeScript client for Google Cloud Secret Manager.

Readme

@agent-base/secret-client

A simple and modern TypeScript client for interacting with Google Cloud Secret Manager.

This package provides a convenient wrapper around the official @google-cloud/secret-manager library, offering a streamlined interface for common secret management operations.

Features

  • Easy-to-use API for creating, retrieving, and checking existence of secrets.
  • Strongly-typed for enhanced developer experience with TypeScript.
  • Configurable for Google Cloud Project ID and credentials.
  • Designed for ES Module environments.

Installation

pnpm install @agent-base/secret-client
# or
yarn add @agent-base/secret-client
# or
npm install @agent-base/secret-client

Prerequisites

Before using this client, ensure you have:

  1. A Google Cloud Platform project.
  2. The Secret Manager API enabled for your project.
  3. Authentication configured. This can be through:
    • Application Default Credentials (ADC) by running gcloud auth application-default login.
    • A service account key JSON file.

Usage

import { GoogleSecretManager } from '@agent-base/secret-client';

async function main() {
  // Initialize the client
  // Option 1: Using Application Default Credentials (ADC)
  const gsmClient = new GoogleSecretManager({
    projectId: 'your-gcp-project-id',
  });

  // Option 2: Using a service account key
  /*
  const credentials = {
    client_email: 'your-service-account-email@your-project-id.iam.gserviceaccount.com',
    private_key: '-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n',
  };
  const gsmClientWithCreds = new GoogleSecretManager({
    projectId: 'your-gcp-project-id',
    credentials,
  });
  */

  const secretId = 'my-api-key';
  const secretValue = 's3cr3tV@lu3';

  try {
    // Store a secret (creates if not exists, then adds a new version)
    await gsmClient.storeSecret(secretId, secretValue);
    console.log(`Secret '${secretId}' stored successfully.`);

    // Retrieve the latest version of the secret
    const retrievedValue = await gsmClient.getSecret(secretId);
    if (retrievedValue !== null) {
      console.log(`Retrieved secret '${secretId}': ${retrievedValue}`);
    } else {
      console.log(`Secret '${secretId}' not found or has no value.`);
    }

    // Check if a secret exists
    const exists = await gsmClient.secretExists(secretId);
    console.log(`Secret '${secretId}' exists: ${exists}`);

    // Example: Storing another version
    await gsmClient.storeSecret(secretId, 'newS3cr3tV@lu3_v2');
    console.log(`Stored new version for secret '${secretId}'.`);
    const updatedValue = await gsmClient.getSecret(secretId);
    console.log(`Retrieved updated secret '${secretId}': ${updatedValue}`);


    // Attempt to retrieve a non-existent secret
    const nonExistentSecret = await gsmClient.getSecret('non-existent-secret');
    console.log(`Value of 'non-existent-secret': ${nonExistentSecret}`); // Expected: null

  } catch (error) {
    console.error('An error occurred:', error);
  }
}

main();

API

new GoogleSecretManager(config: GoogleSecretManagerConfig)

Creates a new instance of the GoogleSecretManager client.

Config:

  • projectId: string: Your Google Cloud Project ID.
  • credentials?: { client_email: string; private_key: string; }: Optional. Service account credentials. If not provided, ADC will be used.

async storeSecret(secretId: string, value: string): Promise<void>

Stores a secret value.

  • If the secret does not exist, it creates the secret and adds the value as the first version.
  • If the secret exists, it adds a new version with the provided value.

async getSecret(secretId: string): Promise<string | null>

Retrieves the latest version of a secret's value. Returns null if the secret or version is not found, or if the version has no data.

async secretExists(secretId: string): Promise<boolean>

Checks if a secret with the given secretId exists.

Error Handling

The client methods may throw errors originating from the @google-cloud/secret-manager library or custom errors like GoogleSecretManagerError for configuration issues.

Contributing

Contributions are welcome! Please see the main repository's contributing guidelines.

License

MIT