SDK — Environments
List Environments
Section titled “List Environments”const envs = await pb.environments.list({ vault: 'my-app', // optional});Returns an array of EnvironmentData:
interface EnvironmentData { id: string; vault_id: string; name: string; description: string | null; is_default: boolean; created_at: string;}Create an Environment
Section titled “Create an Environment”const env = await pb.environments.create('staging', { vault: 'my-app', description: 'Staging environment',});Options
Section titled “Options”interface CreateEnvironmentOptions { vault?: string; description?: string;}Delete an Environment
Section titled “Delete an Environment”await pb.environments.delete('staging', { vault: 'my-app',});Clone an Environment
Section titled “Clone an Environment”const result = await pb.environments.clone('production', 'staging', { vault: 'my-app',});console.log(`Cloned ${result.created} secrets`);Options
Section titled “Options”interface CloneEnvironmentOptions { vault?: string;}Copies all secrets from the source environment to the target. The target environment must already exist.
Resolve Environment Name
Section titled “Resolve Environment Name”const envId = await pb.environments.resolve('production', { vault: 'my-app',});// Returns: "550e8400-e29b-..."Resolves an environment name to its UUID. Used internally by the secrets resource.
Example: Multi-Environment Setup
Section titled “Example: Multi-Environment Setup”import { PassBox } from '@pabox/sdk';
const pb = await PassBox.login({ email, password });pb.setDefaultVault('my-app');
// Create environmentsawait pb.environments.create('staging', { description: 'Pre-production' });await pb.environments.create('production', { description: 'Live' });
// Set environment-specific secretsawait pb.secrets.set('DATABASE_URL', 'postgres://dev/db', { env: 'development' });await pb.secrets.set('DATABASE_URL', 'postgres://staging/db', { env: 'staging' });await pb.secrets.set('DATABASE_URL', 'postgres://prod/db', { env: 'production' });
// Clone staging to production (for initial setup)await pb.environments.clone('production', 'staging');
// Read from specific environmentconst prodDb = await pb.secrets.get('DATABASE_URL', { env: 'production' });