# Available Functions

Kusho provides a set of powerful functions to use in your pre-run scripts. These functions are designed to help you manage variables, make API requests, and log debug information. Let's explore each function in detail:

### debug Function

The `debug` function is used for logging messages during script execution. It's particularly useful for troubleshooting and monitoring the flow of your pre-run script.

```javascript
/**
 * Logs a debug message to the console and the Kusho debug log.
 * 
 * @function debug
 * @param {...*} args - The message or messages to log. Can be strings, numbers, objects, or any other type.
 * @example
 * debug('Starting pre-run script');
 * debug('User ID:', userId, 'Request body:', requestBody);
 */
function debug(...args) {
    // Implementation details
}

// Usage examples
debug('Pre-run script initiated');
debug('Current timestamp:', Date.now());
debug('Config:', { env: 'production', feature_flags: { new_ui: true } });
```

### setVariables Function

The `setVariables` function allows you to set or update variables that can be used across your tests. This is particularly useful for storing configuration data, test parameters, or dynamically generated values.

```javascript
/**
 * Sets or updates variables for use in subsequent tests.
 * 
 * @function setVariables
 * @param {Object} variables - An object containing key-value pairs for the variables to set or update.
 * @example
 * setVariables({ apiKey: 'abc123', userId: 42 });
 */
function setVariables(variables) {
    // Implementation details
}

// Usage examples
setVariables({ baseUrl: 'https://api.kusho.com/v2' });
setVariables({ 
    authToken: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
    requestTimeout: 5000
});
```

### getVariables Function

The `getVariables` function retrieves the current values of variables set in your Kusho environment. This function is asynchronous, reflecting the potential need to fetch variables from a remote source.

```javascript
/**
 * Retrieves the current values of variables set in the Kusho environment.
 * 
 * @async
 * @function getVariables
 * @returns {Promise<Object>} A promise that resolves with an object containing the current key-value pairs of the variables.
 * @example
 * const variables = await getVariables();
 * console.log(variables.apiKey); // Outputs the value of apiKey
 */
async function getVariables() {
    // Implementation details
}

// Usage example
async function setupEnvironment() {
    const vars = await getVariables();
    debug('Current API version:', vars.apiVersion);
    if (vars.environment === 'production') {
        setVariables({ logLevel: 'error' });
    }
}
```

### makeRequest Function

The `makeRequest` function allows you to make HTTP requests directly from your pre-run script. This can be useful for fetching configuration data, warming up APIs, or performing any necessary setup that requires communication with external services.

```javascript
/**
 * Makes an HTTP request using the provided configuration.
 * 
 * @async
 * @function makeRequest
 * @param {Object} request - The request configuration object.
 * @param {string} request.method - The HTTP method (e.g., 'GET', 'POST', 'PUT', 'DELETE').
 * @param {string} request.url - The full URL for the API endpoint.
 * @param {Object} [request.headers] - An object containing request headers.
 * @param {Object|string} [request.data] - The data to be sent in the request body.
 * @returns {Promise<Object>} A promise that resolves with the API response.
 * @example
 * const response = await makeRequest({
 *     method: 'POST',
 *     url: 'https://api.kusho.com/auth',
 *     headers: { 'Content-Type': 'application/json' },
 *     data: { username: 'testuser', password: 'password123' }
 * });
 */
async function makeRequest(request) {
    // Implementation details
}

// Usage example
async function authenticateUser() {
    const authResponse = await makeRequest({
        method: 'POST',
        url: 'https://api.kusho.com/auth',
        headers: { 'Content-Type': 'application/json' },
        data: { username: 'testuser', password: 'password123' }
    });
    
    if (authResponse.status === 200) {
        setVariables({ authToken: authResponse.data.token });
        debug('Authentication successful');
    } else {
        debug('Authentication failed:', authResponse.status);
    }
}
```
