@compass/variables

This package provides functionalities to interact with the automation context in Compass. It allows you to retrieve and set variables within the context.

Usage

import variables from "@compass/variables";

API Reference

variables.get(key: string, scope?: string)

Retrieve a variable from the automation context.

  • key (required, string): The key of the variable to retrieve.

  • scope (optional, string): The scope of the variable to retrieve.

Returns the value of the variable. Returns null if the variable does not exist.

variables.set(key: string, value: any, scope?: string)

Set a variable in the automation context.

  • key (required, string): The key of the variable to set.

  • value (required, any): The value of the variable to set.

  • scope (optional, string): The scope of the variable to set.

Returns the value of the variable.

Examples

To retrieve a variable from the automation context:

import variables from "@compass/variables";

export default async function() {
    const key = 'variableKey';
    const scope = 'local';
    const value = variables.get(key, scope);
    return { value };
}

To set a variable in the automation context:

import variables from "@compass/variables";

export default async function() {
    const key = 'variableKey';
    const value = 'Hello, World!';
    const scope = 'local';
    const setValue = variables.set(key, value, scope);
    return { setValue };
}

Last updated