Skip to main content
The EnvironmentManager provides methods to create and manage environments with variables and secrets for your workspace.

Access the manager

Access the environment manager through a workspace instance:
const workspace = yasumu.workspaces.getActiveWorkspace();
const envManager = workspace.environments;

// Create an environment
const env = await envManager.create({
  name: 'Development',
});

await env.setActive();

Methods

create()

Creates a new environment.
const env = await workspace.environments.create({
  name: 'Production',
});

console.log(`Created environment: ${env.name}`);
data
EnvironmentCreateOptions
required
return
Promise<Environment>
The created environment instance

list()

Lists all environments in the workspace.
const environments = await workspace.environments.list();

for (const env of environments) {
  console.log(env.name);
}
return
Promise<Environment[]>
Array of environment instances

get()

Retrieves an environment by ID.
const env = await workspace.environments.get('env-id');

if (env) {
  console.log(env.name);
} else {
  console.log('Environment not found');
}
id
string
required
ID of the environment
return
Promise<Environment | null>
The environment instance, or null if not found

update()

Updates an environment.
const updated = await workspace.environments.update('env-id', {
  name: 'Production (Updated)',
});
id
string
required
ID of the environment to update
data
Partial<EnvironmentUpdateOptions>
required
options
object
return
Promise<Environment>
The updated environment instance

delete()

Deletes an environment.
await workspace.environments.delete('env-id');
id
string
required
ID of the environment to delete
return
Promise<void>
Resolves when the environment is deleted

getActiveEnvironment()

Returns the currently active environment.
const active = await workspace.environments.getActiveEnvironment();

if (active) {
  console.log(`Active environment: ${active.name}`);
} else {
  console.log('No active environment');
}
return
Promise<Environment | null>
The active environment, or null if none is active

setActiveEnvironment()

Sets an environment as active.
await workspace.environments.setActiveEnvironment('env-id');
id
string
required
ID of the environment to activate
return
Promise<void>
Resolves when the environment is activated

Environment class

The Environment class represents a single environment with variables and secrets.

Properties

const env = await workspace.environments.get('env-id');

console.log(env.id);
console.log(env.name);
console.log(env.workspace);
id
string
Unique identifier for the environment
name
string
Display name of the environment
workspace
Workspace
The workspace that owns this environment
variables
EnvironmentVariable
Manager for environment variables
secrets
EnvironmentVariable
Manager for environment secrets

Methods

setActive()

Sets this environment as the active one.
await env.setActive();
return
Promise<void>
Resolves when the environment is activated

update()

Updates this environment.
await env.update({
  name: 'Updated Name',
});
data
Partial<EnvironmentUpdateOptions>
required
Fields to update
options
object
return
Promise<Environment>
The updated environment instance

interpolate()

Interpolates variables and secrets in a string using {{variableName}} syntax.
const url = env.interpolate('https://{{API_HOST}}/api/v1');
console.log(url); // https://api.example.com/api/v1
Supports multiple syntaxes:
  • {{variableName}} - Looks in variables first, then secrets
  • {{variables.variableName}} - Looks only in variables
  • {{secrets.secretName}} - Looks only in secrets
str
string
required
String with interpolation placeholders
return
string
String with variables replaced by their values

toJSON()

Converts the environment to a plain object.
const data = env.toJSON();
console.log(data);
return
EnvironmentData
Plain object representation of the environment

Managing variables

Environment variables are stored in the variables property:
const env = await workspace.environments.get('env-id');

// Set a variable
await env.variables.set('API_HOST', 'api.example.com');
await env.variables.set('API_PORT', '3000');

// Get a variable
const host = env.variables.get('API_HOST');
console.log(host?.value); // api.example.com

// List all variables
const allVars = env.variables.toJSON();
console.log(allVars);

// Delete a variable
await env.variables.delete('API_PORT');

Managing secrets

Secrets work the same as variables but are stored separately:
const env = await workspace.environments.get('env-id');

// Set a secret
await env.secrets.set('API_KEY', 'secret-key-12345');
await env.secrets.set('DB_PASSWORD', 'secure-password');

// Get a secret
const apiKey = env.secrets.get('API_KEY');
console.log(apiKey?.value);

// List all secrets
const allSecrets = env.secrets.toJSON();

Variable interpolation

Use environment variables in REST entity URLs and other fields:
const dev = await workspace.environments.create({
  name: 'Development',
});

await dev.variables.set('API_URL', 'http://localhost:3000');
await dev.secrets.set('API_KEY', 'dev-key-123');

const prod = await workspace.environments.create({
  name: 'Production',
});

await prod.variables.set('API_URL', 'https://api.example.com');
await prod.secrets.set('API_KEY', 'prod-key-xyz');

// Create REST entity with variables
const entity = await workspace.rest.create({
  name: 'Get Users',
  url: '{{API_URL}}/users',
  method: 'GET',
  headers: [
    {
      key: 'Authorization',
      value: 'Bearer {{API_KEY}}',
      enabled: true,
    },
  ],
});

// Activate dev environment
await dev.setActive();
const active = await workspace.environments.getActiveEnvironment();

// Interpolate variables
const url = active.interpolate(entity.url);
console.log(url); // http://localhost:3000/users

const authHeader = active.interpolate('Bearer {{API_KEY}}');
console.log(authHeader); // Bearer dev-key-123

Example usage

// Create multiple environments
const dev = await workspace.environments.create({ name: 'Development' });
const staging = await workspace.environments.create({ name: 'Staging' });
const prod = await workspace.environments.create({ name: 'Production' });

// Configure development
await dev.variables.set('API_URL', 'http://localhost:3000');
await dev.variables.set('DEBUG', 'true');
await dev.secrets.set('DB_PASSWORD', 'dev-password');
await dev.secrets.set('API_KEY', 'dev-key-123');

// Configure production
await prod.variables.set('API_URL', 'https://api.example.com');
await prod.variables.set('DEBUG', 'false');
await prod.secrets.set('DB_PASSWORD', 'prod-secure-password');
await prod.secrets.set('API_KEY', 'prod-key-xyz');

// Set active environment
await dev.setActive();

// Use variables in REST entities
const entity = await workspace.rest.create({
  name: 'Create User',
  url: '{{API_URL}}/users',
  method: 'POST',
  headers: [
    {
      key: 'Authorization',
      value: 'Bearer {{API_KEY}}',
      enabled: true,
    },
    {
      key: 'Content-Type',
      value: 'application/json',
      enabled: true,
    },
  ],
});

// Switch to production
await prod.setActive();
const activeEnv = await workspace.environments.getActiveEnvironment();
console.log(`Active: ${activeEnv.name}`);

// List all environments
const allEnvs = await workspace.environments.list();
console.log(`Total environments: ${allEnvs.length}`);

Workspace

Workspace management

RestModule

REST API testing

Build docs developers (and LLMs) love