Skip to content

Environment

Environment

Environment = object

A saved immutable Environment.

Properties

id

readonly id: ID

The ID of the environment.

name

readonly name: string

The name of the environment.

variables

readonly variables: EnvironmentVariable[]

The variables of the environment.

version

readonly version: number

The version of the environment.


EnvironmentSDK

EnvironmentSDK = object

The SDK for the Environment service.

Methods

createEnvironment()

createEnvironment(input: CreateEnvironmentInput): Promise<Environment>

Create a new environment.

Parameters
ParameterTypeDescription
inputCreateEnvironmentInputThe input for the creation.
Returns

Promise<Environment>

The created environment.

deleteEnvironment()

deleteEnvironment(id: ID): Promise<void>

Delete an environment by its ID.

Parameters
ParameterTypeDescription
idIDThe ID of the environment.
Returns

Promise<void>

getEnvironment()

getEnvironment(id: ID): Promise<Environment | undefined>

Get an environment by its ID.

Parameters
ParameterTypeDescription
idIDThe ID of the environment.
Returns

Promise<Environment | undefined>

The environment or undefined if not found.

getEnvironments()

getEnvironments(): Promise<Environment[]>

Get all the environments.

Returns

Promise<Environment[]>

An array of Environment

getVar()

getVar(name: string): string | undefined

Get the value of an environment variable.

Parameters
ParameterTypeDescription
namestringThe name of the environment variable.
Returns

string | undefined

The value of the environment variable.

getVars()

getVars(): EnvironmentVariable[]

Get all the environment variables. It includes the global environment and the selected environment. Those variables can change over time so avoid caching them.

Returns

EnvironmentVariable[]

An array of EnvironmentVariable

setVar()

setVar(input: SetVarInput): Promise<void>

Sets an environment variable to a given value. This will override any existing value. The environment variable can be set either on the currently selected environment or the global environment.

Parameters
ParameterType
inputSetVarInput
Returns

Promise<void>

Throws

If trying to set when a project is not selected.

Throws

If trying to set when an environment is not selected (with global: false).

Example
js
await sdk.env.setVar({
  name: "USER_SECRET",
  value: "my secret value",
  secret: true,
  global: false
});
updateEnvironment()

updateEnvironment(id: ID, input: UpdateEnvironmentInput): Promise<Environment>

Update an environment.

Parameters
ParameterTypeDescription
idIDThe ID of the environment.
inputUpdateEnvironmentInputThe input for the update.
Returns

Promise<Environment>

The updated environment.

Throws

If the version passed in is not equal to the current version of the environment.

Example
js
const environment = await sdk.env.getEnvironment(id);
await sdk.env.updateEnvironment(id, {
  version: environment.version,
  name: "new name",
  variables: [{ name: "USER_SECRET", value: "new secret value", secret: true }],
});

EnvironmentVariable

EnvironmentVariable = object

A saved immutable Finding.

Properties

isSecret

readonly isSecret: boolean

If the environment variable is a secret

name

readonly name: string

The name of the environment variable

value

readonly value: string

The value of the environment variable


SetVarInput

SetVarInput = object

Input for the setVar of EnvironmentSDK.

Properties

env?

optional env: string

The name of the Environment to set the variable on. This will take precedence over the global flag if provided.

global

global: boolean

If the environment variable should be set on the global environment or the currently selected environment. By default, it will be set globally.

Default
ts
true
name

name: string

Name of the environment variable

secret

secret: boolean

If the environment variable should be treated as secret.

Default
ts
false
value

value: string

Value of the environment variable