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
Show EnvironmentCreateOptions properties
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 );
}
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' );
}
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 of the environment to update
data
Partial<EnvironmentUpdateOptions>
required
Show EnvironmentUpdateOptions properties
Updated name for the environment
If true, suppresses the onEnvironmentUpdated event
The updated environment instance
delete()
Deletes an environment.
await workspace . environments . delete ( 'env-id' );
ID of the environment to delete
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 of the environment to activate
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 );
Unique identifier for the environment
Display name of the environment
The workspace that owns this environment
Manager for environment variables
Manager for environment secrets
Methods
setActive()
Sets this environment as the active one.
Resolves when the environment is activated
update()
Updates this environment.
await env . update ({
name: 'Updated Name' ,
});
data
Partial<EnvironmentUpdateOptions>
required
Fields to update
If true, suppresses the onEnvironmentUpdated event
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
String with interpolation placeholders
String with variables replaced by their values
toJSON()
Converts the environment to a plain object.
const data = env . toJSON ();
console . log ( data );
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