mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 23:43:15 +01:00
feat/rename collectionVariables variable name to runtimeVariables (#2638)
* pr review changes * collection root object in export json * import environment updates * tests run execution order fix for collection runs * updated validations * collectionVariables -> runtimeVariables * removed husky, adjusted indentation --------- Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
parent
e60aaf2ea9
commit
ab9bcbe5ed
@ -1,4 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npx pretty-quick --staged
|
@ -73,7 +73,7 @@ const GenerateCodeItem = ({ collection, item, onClose }) => {
|
||||
const interpolatedUrl = interpolateUrl({
|
||||
url: requestUrl,
|
||||
envVars,
|
||||
collectionVariables: collection.collectionVariables,
|
||||
runtimeVariables: collection.runtimeVariables,
|
||||
processEnvVars: collection.processEnvVariables
|
||||
});
|
||||
|
||||
|
@ -62,10 +62,10 @@ const EnvVariables = ({ collection, theme }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const CollectionVariables = ({ collection, theme }) => {
|
||||
const collectionVariablesFound = Object.keys(collection.collectionVariables).length > 0;
|
||||
const RuntimeVariables = ({ collection, theme }) => {
|
||||
const runtimeVariablesFound = Object.keys(collection.runtimeVariables).length > 0;
|
||||
|
||||
const collectionVariableArray = Object.entries(collection.collectionVariables).map(([name, value]) => ({
|
||||
const runtimeVariableArray = Object.entries(collection.runtimeVariables).map(([name, value]) => ({
|
||||
name,
|
||||
value,
|
||||
secret: false
|
||||
@ -73,11 +73,11 @@ const CollectionVariables = ({ collection, theme }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<h1 className="font-semibold mb-2">Collection Variables</h1>
|
||||
{collectionVariablesFound ? (
|
||||
<KeyValueExplorer data={collectionVariableArray} theme={theme} />
|
||||
<h1 className="font-semibold mb-2">Runtime Variables</h1>
|
||||
{runtimeVariablesFound ? (
|
||||
<KeyValueExplorer data={runtimeVariableArray} theme={theme} />
|
||||
) : (
|
||||
<div className="muted text-xs">No collection variables found</div>
|
||||
<div className="muted text-xs">No runtime variables found</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
@ -90,13 +90,13 @@ const VariablesEditor = ({ collection }) => {
|
||||
|
||||
return (
|
||||
<StyledWrapper className="px-4 py-4">
|
||||
<CollectionVariables collection={collection} theme={reactInspectorTheme} />
|
||||
<RuntimeVariables collection={collection} theme={reactInspectorTheme} />
|
||||
<EnvVariables collection={collection} theme={reactInspectorTheme} />
|
||||
|
||||
<div className="mt-8 muted text-xs">
|
||||
Note: As of today, collection variables can only be set via the API -{' '}
|
||||
<span className="font-medium">getVar()</span> and <span className="font-medium">setVar()</span>. <br />
|
||||
In the next release, we will add a UI to set and modify collection variables.
|
||||
Note: As of today, runtime variables can only be set via the API - <span className="font-medium">getVar()</span>{' '}
|
||||
and <span className="font-medium">setVar()</span>. <br />
|
||||
In the next release, we will add a UI to set and modify runtime variables.
|
||||
</div>
|
||||
</StyledWrapper>
|
||||
);
|
||||
|
@ -195,7 +195,7 @@ export const sendCollectionOauth2Request = (collectionUid, itemUid) => (dispatch
|
||||
const externalSecrets = getExternalCollectionSecretsForActiveEnvironment({ collection });
|
||||
const secretVariables = getFormattedCollectionSecretVariables({ externalSecrets });
|
||||
|
||||
_sendCollectionOauth2Request(collection, environment, collectionCopy.collectionVariables, itemUid, secretVariables)
|
||||
_sendCollectionOauth2Request(collection, environment, collectionCopy.runtimeVariables, itemUid, secretVariables)
|
||||
.then((response) => {
|
||||
if (response?.data?.error) {
|
||||
toast.error(response?.data?.error);
|
||||
@ -224,7 +224,7 @@ export const sendRequest = (item, collectionUid) => (dispatch, getState) => {
|
||||
const collectionCopy = cloneDeep(collection);
|
||||
|
||||
const environment = findEnvironmentInCollection(collectionCopy, collectionCopy.activeEnvironmentUid);
|
||||
sendNetworkRequest(itemCopy, collectionCopy, environment, collectionCopy.collectionVariables)
|
||||
sendNetworkRequest(itemCopy, collectionCopy, environment, collectionCopy.runtimeVariables)
|
||||
.then((response) => {
|
||||
return dispatch(
|
||||
responseReceived({
|
||||
@ -314,7 +314,7 @@ export const runCollectionFolder = (collectionUid, folderUid, recursive) => (dis
|
||||
folder,
|
||||
collectionCopy,
|
||||
environment,
|
||||
collectionCopy.collectionVariables,
|
||||
collectionCopy.runtimeVariables,
|
||||
recursive
|
||||
)
|
||||
.then(resolve)
|
||||
@ -1036,7 +1036,7 @@ export const openCollectionEvent = (uid, pathname, brunoConfig) => (dispatch, ge
|
||||
name: brunoConfig.name,
|
||||
pathname: pathname,
|
||||
items: [],
|
||||
collectionVariables: {},
|
||||
runtimeVariables: {},
|
||||
brunoConfig: brunoConfig
|
||||
};
|
||||
|
||||
|
@ -200,7 +200,7 @@ export const collectionsSlice = createSlice({
|
||||
}
|
||||
},
|
||||
scriptEnvironmentUpdateEvent: (state, action) => {
|
||||
const { collectionUid, envVariables, collectionVariables } = action.payload;
|
||||
const { collectionUid, envVariables, runtimeVariables } = action.payload;
|
||||
const collection = findCollectionByUid(state.collections, collectionUid);
|
||||
|
||||
if (collection) {
|
||||
@ -230,7 +230,7 @@ export const collectionsSlice = createSlice({
|
||||
});
|
||||
}
|
||||
|
||||
collection.collectionVariables = collectionVariables;
|
||||
collection.runtimeVariables = runtimeVariables;
|
||||
}
|
||||
},
|
||||
processEnvUpdateEvent: (state, action) => {
|
||||
|
@ -798,7 +798,7 @@ export const getAllVariables = (collection, item) => {
|
||||
return {
|
||||
...environmentVariables,
|
||||
...requestVariables,
|
||||
...collection.collectionVariables,
|
||||
...collection.runtimeVariables,
|
||||
pathParams: {
|
||||
...pathParams
|
||||
},
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { safeStringifyJSON } from 'utils/common';
|
||||
|
||||
export const sendNetworkRequest = async (item, collection, environment, collectionVariables) => {
|
||||
export const sendNetworkRequest = async (item, collection, environment, runtimeVariables) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (['http-request', 'graphql-request'].includes(item.type)) {
|
||||
sendHttpRequest(item, collection, environment, collectionVariables)
|
||||
sendHttpRequest(item, collection, environment, runtimeVariables)
|
||||
.then((response) => {
|
||||
resolve({
|
||||
state: 'success',
|
||||
@ -22,22 +22,22 @@ export const sendNetworkRequest = async (item, collection, environment, collecti
|
||||
});
|
||||
};
|
||||
|
||||
const sendHttpRequest = async (item, collection, environment, collectionVariables) => {
|
||||
const sendHttpRequest = async (item, collection, environment, runtimeVariables) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
ipcRenderer
|
||||
.invoke('send-http-request', item, collection, environment, collectionVariables)
|
||||
.invoke('send-http-request', item, collection, environment, runtimeVariables)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
export const sendCollectionOauth2Request = async (collection, environment, collectionVariables) => {
|
||||
export const sendCollectionOauth2Request = async (collection, environment, runtimeVariables) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { ipcRenderer } = window;
|
||||
ipcRenderer
|
||||
.invoke('send-collection-oauth2-request', collection, environment, collectionVariables)
|
||||
.invoke('send-collection-oauth2-request', collection, environment, runtimeVariables)
|
||||
.then(resolve)
|
||||
.catch(reject);
|
||||
});
|
||||
|
@ -107,14 +107,14 @@ export const isValidUrl = (url) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const interpolateUrl = ({ url, envVars, collectionVariables, processEnvVars }) => {
|
||||
export const interpolateUrl = ({ url, envVars, runtimeVariables, processEnvVars }) => {
|
||||
if (!url || !url.length || typeof url !== 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
return interpolate(url, {
|
||||
...envVars,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...processEnvVars
|
||||
|
@ -129,10 +129,10 @@ describe('Url Utils - interpolateUrl, interpolateUrlPathParams', () => {
|
||||
const expectedUrl = 'https://example.com/api/:id/path?foo=foo_value&bar=bar_value&baz=baz_value';
|
||||
|
||||
const envVars = { host: 'https://example.com', foo: 'foo_value' };
|
||||
const collectionVariables = { bar: 'bar_value' };
|
||||
const runtimeVariables = { bar: 'bar_value' };
|
||||
const processEnvVars = { baz: 'baz_value' };
|
||||
|
||||
const result = interpolateUrl({ url, envVars, collectionVariables, processEnvVars });
|
||||
const result = interpolateUrl({ url, envVars, runtimeVariables, processEnvVars });
|
||||
|
||||
expect(result).toEqual(expectedUrl);
|
||||
});
|
||||
@ -153,10 +153,10 @@ describe('Url Utils - interpolateUrl, interpolateUrlPathParams', () => {
|
||||
const expectedUrl = 'https://example.com/api/123/path?foo=foo_value&bar=bar_value&baz=baz_value';
|
||||
|
||||
const envVars = { host: 'https://example.com', foo: 'foo_value' };
|
||||
const collectionVariables = { bar: 'bar_value' };
|
||||
const runtimeVariables = { bar: 'bar_value' };
|
||||
const processEnvVars = { baz: 'baz_value' };
|
||||
|
||||
const intermediateResult = interpolateUrl({ url, envVars, collectionVariables, processEnvVars });
|
||||
const intermediateResult = interpolateUrl({ url, envVars, runtimeVariables, processEnvVars });
|
||||
const result = interpolateUrlPathParams(intermediateResult, params);
|
||||
|
||||
expect(result).toEqual(expectedUrl);
|
||||
|
@ -312,7 +312,7 @@ const handler = async function (argv) {
|
||||
recursive = true;
|
||||
}
|
||||
|
||||
const collectionVariables = {};
|
||||
const runtimeVariables = {};
|
||||
let envVars = {};
|
||||
|
||||
if (env) {
|
||||
@ -462,7 +462,7 @@ const handler = async function (argv) {
|
||||
bruFilepath,
|
||||
bruJson,
|
||||
collectionPath,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
envVars,
|
||||
processEnvVars,
|
||||
brunoConfig,
|
||||
|
@ -1,13 +1,13 @@
|
||||
const { forOwn, cloneDeep } = require('lodash');
|
||||
const { interpolate } = require('@usebruno/common');
|
||||
|
||||
const interpolateString = (str, { envVars, collectionVariables, processEnvVars }) => {
|
||||
const interpolateString = (str, { envVars, runtimeVariables, processEnvVars }) => {
|
||||
if (!str || !str.length || typeof str !== 'string') {
|
||||
return str;
|
||||
}
|
||||
|
||||
processEnvVars = processEnvVars || {};
|
||||
collectionVariables = collectionVariables || {};
|
||||
runtimeVariables = runtimeVariables || {};
|
||||
|
||||
// we clone envVars because we don't want to modify the original object
|
||||
envVars = envVars ? cloneDeep(envVars) : {};
|
||||
@ -24,10 +24,10 @@ const interpolateString = (str, { envVars, collectionVariables, processEnvVars }
|
||||
});
|
||||
});
|
||||
|
||||
// collectionVariables take precedence over envVars
|
||||
// runtimeVariables take precedence over envVars
|
||||
const combinedVars = {
|
||||
...envVars,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...processEnvVars
|
||||
|
@ -12,7 +12,7 @@ const getContentType = (headers = {}) => {
|
||||
return contentType;
|
||||
};
|
||||
|
||||
const interpolateVars = (request, envVars = {}, collectionVariables = {}, processEnvVars = {}) => {
|
||||
const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEnvVars = {}) => {
|
||||
// we clone envVars because we don't want to modify the original object
|
||||
envVars = cloneDeep(envVars);
|
||||
|
||||
@ -33,10 +33,10 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces
|
||||
return str;
|
||||
}
|
||||
|
||||
// collectionVariables take precedence over envVars
|
||||
// runtimeVariables take precedence over envVars
|
||||
const combinedVars = {
|
||||
...envVars,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...processEnvVars
|
||||
|
@ -25,7 +25,7 @@ const runSingleRequest = async function (
|
||||
filename,
|
||||
bruJson,
|
||||
collectionPath,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
envVariables,
|
||||
processEnvVars,
|
||||
brunoConfig,
|
||||
@ -62,7 +62,7 @@ const runSingleRequest = async function (
|
||||
preRequestVars,
|
||||
request,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
processEnvVars
|
||||
);
|
||||
@ -79,7 +79,7 @@ const runSingleRequest = async function (
|
||||
decomment(requestScriptFile),
|
||||
request,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
null,
|
||||
processEnvVars,
|
||||
@ -91,7 +91,7 @@ const runSingleRequest = async function (
|
||||
}
|
||||
|
||||
// interpolate variables inside request
|
||||
interpolateVars(request, envVariables, collectionVariables, processEnvVars);
|
||||
interpolateVars(request, envVariables, runtimeVariables, processEnvVars);
|
||||
|
||||
if (!protocolRegex.test(request.url)) {
|
||||
request.url = `http://${request.url}`;
|
||||
@ -120,7 +120,7 @@ const runSingleRequest = async function (
|
||||
|
||||
const interpolationOptions = {
|
||||
envVars: envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars
|
||||
};
|
||||
|
||||
@ -282,7 +282,7 @@ const runSingleRequest = async function (
|
||||
request,
|
||||
response,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
processEnvVars
|
||||
);
|
||||
@ -300,7 +300,7 @@ const runSingleRequest = async function (
|
||||
request,
|
||||
response,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
null,
|
||||
processEnvVars,
|
||||
@ -321,7 +321,7 @@ const runSingleRequest = async function (
|
||||
request,
|
||||
response,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars
|
||||
);
|
||||
|
||||
@ -345,7 +345,7 @@ const runSingleRequest = async function (
|
||||
request,
|
||||
response,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
null,
|
||||
processEnvVars,
|
||||
|
@ -87,7 +87,7 @@ const configureRequest = async (
|
||||
collectionUid,
|
||||
request,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath
|
||||
) => {
|
||||
@ -118,7 +118,7 @@ const configureRequest = async (
|
||||
const brunoConfig = getBrunoConfig(collectionUid);
|
||||
const interpolationOptions = {
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars
|
||||
};
|
||||
|
||||
@ -211,7 +211,7 @@ const configureRequest = async (
|
||||
let requestCopy = cloneDeep(request);
|
||||
switch (request?.oauth2?.grantType) {
|
||||
case 'authorization_code':
|
||||
interpolateVars(requestCopy, envVars, collectionVariables, processEnvVars);
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars);
|
||||
const { data: authorizationCodeData, url: authorizationCodeAccessTokenUrl } =
|
||||
await resolveOAuth2AuthorizationCodeAccessToken(requestCopy, collectionUid);
|
||||
request.method = 'POST';
|
||||
@ -220,7 +220,7 @@ const configureRequest = async (
|
||||
request.url = authorizationCodeAccessTokenUrl;
|
||||
break;
|
||||
case 'client_credentials':
|
||||
interpolateVars(requestCopy, envVars, collectionVariables, processEnvVars);
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars);
|
||||
const { data: clientCredentialsData, url: clientCredentialsAccessTokenUrl } =
|
||||
await transformClientCredentialsRequest(requestCopy);
|
||||
request.method = 'POST';
|
||||
@ -229,7 +229,7 @@ const configureRequest = async (
|
||||
request.url = clientCredentialsAccessTokenUrl;
|
||||
break;
|
||||
case 'password':
|
||||
interpolateVars(requestCopy, envVars, collectionVariables, processEnvVars);
|
||||
interpolateVars(requestCopy, envVars, runtimeVariables, processEnvVars);
|
||||
const { data: passwordData, url: passwordAccessTokenUrl } = await transformPasswordCredentialsRequest(
|
||||
requestCopy
|
||||
);
|
||||
@ -308,7 +308,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
) => {
|
||||
@ -320,7 +320,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
preRequestVars,
|
||||
request,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
processEnvVars
|
||||
);
|
||||
@ -335,7 +335,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
decomment(requestScript),
|
||||
request,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
@ -344,14 +344,14 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
|
||||
mainWindow.webContents.send('main:script-environment-update', {
|
||||
envVariables: scriptResult.envVariables,
|
||||
collectionVariables: scriptResult.collectionVariables,
|
||||
runtimeVariables: scriptResult.runtimeVariables,
|
||||
requestUid,
|
||||
collectionUid
|
||||
});
|
||||
}
|
||||
|
||||
// interpolate variables inside request
|
||||
interpolateVars(request, envVars, collectionVariables, processEnvVars);
|
||||
interpolateVars(request, envVars, runtimeVariables, processEnvVars);
|
||||
|
||||
// if this is a graphql request, parse the variables, only after interpolation
|
||||
// https://github.com/usebruno/bruno/issues/884
|
||||
@ -375,7 +375,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
) => {
|
||||
@ -388,7 +388,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
request,
|
||||
response,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
processEnvVars
|
||||
);
|
||||
@ -396,7 +396,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
if (result) {
|
||||
mainWindow.webContents.send('main:script-environment-update', {
|
||||
envVariables: result.envVariables,
|
||||
collectionVariables: result.collectionVariables,
|
||||
runtimeVariables: result.runtimeVariables,
|
||||
requestUid,
|
||||
collectionUid
|
||||
});
|
||||
@ -419,7 +419,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
request,
|
||||
response,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
@ -428,7 +428,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
|
||||
mainWindow.webContents.send('main:script-environment-update', {
|
||||
envVariables: scriptResult.envVariables,
|
||||
collectionVariables: scriptResult.collectionVariables,
|
||||
runtimeVariables: scriptResult.runtimeVariables,
|
||||
requestUid,
|
||||
collectionUid
|
||||
});
|
||||
@ -437,7 +437,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
};
|
||||
|
||||
// handler for sending http request
|
||||
ipcMain.handle('send-http-request', async (event, item, collection, environment, collectionVariables) => {
|
||||
ipcMain.handle('send-http-request', async (event, item, collection, environment, runtimeVariables) => {
|
||||
const collectionUid = collection.uid;
|
||||
const collectionPath = collection.pathname;
|
||||
const cancelTokenUid = uuid();
|
||||
@ -470,7 +470,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
@ -479,7 +479,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionUid,
|
||||
request,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath
|
||||
);
|
||||
@ -564,7 +564,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
@ -578,7 +578,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
request,
|
||||
response,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars
|
||||
);
|
||||
|
||||
@ -603,7 +603,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
request,
|
||||
response,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
@ -620,7 +620,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
|
||||
mainWindow.webContents.send('main:script-environment-update', {
|
||||
envVariables: testResults.envVariables,
|
||||
collectionVariables: testResults.collectionVariables,
|
||||
runtimeVariables: testResults.runtimeVariables,
|
||||
requestUid,
|
||||
collectionUid
|
||||
});
|
||||
@ -642,7 +642,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('send-collection-oauth2-request', async (event, collection, environment, collectionVariables) => {
|
||||
ipcMain.handle('send-collection-oauth2-request', async (event, collection, environment, runtimeVariables) => {
|
||||
try {
|
||||
const collectionUid = collection.uid;
|
||||
const collectionPath = collection.pathname;
|
||||
@ -663,17 +663,17 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
|
||||
interpolateVars(request, envVars, collection.collectionVariables, processEnvVars);
|
||||
interpolateVars(request, envVars, collection.runtimeVariables, processEnvVars);
|
||||
const axiosInstance = await configureRequest(
|
||||
collection.uid,
|
||||
request,
|
||||
envVars,
|
||||
collection.collectionVariables,
|
||||
collection.runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath
|
||||
);
|
||||
@ -699,7 +699,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
@ -756,7 +756,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
const requestUid = uuid();
|
||||
const collectionPath = collection.pathname;
|
||||
const collectionUid = collection.uid;
|
||||
const collectionVariables = collection.collectionVariables;
|
||||
const runtimeVariables = collection.runtimeVariables;
|
||||
const processEnvVars = getProcessEnvVars(collectionUid);
|
||||
const brunoConfig = getBrunoConfig(collection.uid);
|
||||
const scriptingConfig = get(brunoConfig, 'scripts', {});
|
||||
@ -768,17 +768,17 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
|
||||
interpolateVars(request, envVars, collection.collectionVariables, processEnvVars);
|
||||
interpolateVars(request, envVars, collection.runtimeVariables, processEnvVars);
|
||||
const axiosInstance = await configureRequest(
|
||||
collection.uid,
|
||||
request,
|
||||
envVars,
|
||||
collection.collectionVariables,
|
||||
collection.runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath
|
||||
);
|
||||
@ -792,7 +792,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
@ -819,7 +819,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
|
||||
ipcMain.handle(
|
||||
'renderer:run-collection-folder',
|
||||
async (event, folder, collection, environment, collectionVariables, recursive) => {
|
||||
async (event, folder, collection, environment, runtimeVariables, recursive) => {
|
||||
const collectionUid = collection.uid;
|
||||
const collectionPath = collection.pathname;
|
||||
const folderUid = folder ? folder.uid : null;
|
||||
@ -902,7 +902,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
@ -930,7 +930,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionUid,
|
||||
request,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
collectionPath
|
||||
);
|
||||
@ -998,7 +998,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
collectionPath,
|
||||
collectionRoot,
|
||||
collectionUid,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
);
|
||||
@ -1016,7 +1016,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
request,
|
||||
response,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
processEnvVars
|
||||
);
|
||||
|
||||
@ -1040,7 +1040,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
request,
|
||||
response,
|
||||
envVars,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
@ -1055,7 +1055,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
|
||||
mainWindow.webContents.send('main:script-environment-update', {
|
||||
envVariables: testResults.envVariables,
|
||||
collectionVariables: testResults.collectionVariables,
|
||||
runtimeVariables: testResults.runtimeVariables,
|
||||
collectionUid
|
||||
});
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
const { forOwn, cloneDeep } = require('lodash');
|
||||
const { interpolate } = require('@usebruno/common');
|
||||
|
||||
const interpolateString = (str, { envVars, collectionVariables, processEnvVars }) => {
|
||||
const interpolateString = (str, { envVars, runtimeVariables, processEnvVars }) => {
|
||||
if (!str || !str.length || typeof str !== 'string') {
|
||||
return str;
|
||||
}
|
||||
|
||||
processEnvVars = processEnvVars || {};
|
||||
collectionVariables = collectionVariables || {};
|
||||
runtimeVariables = runtimeVariables || {};
|
||||
|
||||
// we clone envVars because we don't want to modify the original object
|
||||
envVars = envVars ? cloneDeep(envVars) : {};
|
||||
@ -24,10 +24,10 @@ const interpolateString = (str, { envVars, collectionVariables, processEnvVars }
|
||||
});
|
||||
});
|
||||
|
||||
// collectionVariables take precedence over envVars
|
||||
// runtimeVariables take precedence over envVars
|
||||
const combinedVars = {
|
||||
...envVars,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...processEnvVars
|
||||
|
@ -12,7 +12,7 @@ const getContentType = (headers = {}) => {
|
||||
return contentType;
|
||||
};
|
||||
|
||||
const interpolateVars = (request, envVars = {}, collectionVariables = {}, processEnvVars = {}) => {
|
||||
const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEnvVars = {}) => {
|
||||
const requestVariables = request?.requestVariables || {};
|
||||
// we clone envVars because we don't want to modify the original object
|
||||
envVars = cloneDeep(envVars);
|
||||
@ -34,11 +34,11 @@ const interpolateVars = (request, envVars = {}, collectionVariables = {}, proces
|
||||
return str;
|
||||
}
|
||||
|
||||
// collectionVariables take precedence over envVars
|
||||
// runtimeVariables take precedence over envVars
|
||||
const combinedVars = {
|
||||
...envVars,
|
||||
...requestVariables,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...processEnvVars
|
||||
|
@ -4,9 +4,9 @@ const { interpolate } = require('@usebruno/common');
|
||||
const variableNameRegex = /^[\w-.]*$/;
|
||||
|
||||
class Bru {
|
||||
constructor(envVariables, collectionVariables, processEnvVars, collectionPath, requestVariables) {
|
||||
constructor(envVariables, runtimeVariables, processEnvVars, collectionPath, requestVariables) {
|
||||
this.envVariables = envVariables || {};
|
||||
this.collectionVariables = collectionVariables || {};
|
||||
this.runtimeVariables = runtimeVariables || {};
|
||||
this.processEnvVars = cloneDeep(processEnvVars || {});
|
||||
this.requestVariables = requestVariables || {};
|
||||
this.collectionPath = collectionPath;
|
||||
@ -20,7 +20,7 @@ class Bru {
|
||||
const combinedVars = {
|
||||
...this.envVariables,
|
||||
...this.requestVariables,
|
||||
...this.collectionVariables,
|
||||
...this.runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...this.processEnvVars
|
||||
@ -60,7 +60,7 @@ class Bru {
|
||||
}
|
||||
|
||||
hasVar(key) {
|
||||
return Object.hasOwn(this.collectionVariables, key);
|
||||
return Object.hasOwn(this.runtimeVariables, key);
|
||||
}
|
||||
|
||||
setVar(key, value) {
|
||||
@ -75,7 +75,7 @@ class Bru {
|
||||
);
|
||||
}
|
||||
|
||||
this.collectionVariables[key] = value;
|
||||
this.runtimeVariables[key] = value;
|
||||
}
|
||||
|
||||
getVar(key) {
|
||||
@ -86,11 +86,11 @@ class Bru {
|
||||
);
|
||||
}
|
||||
|
||||
return this._interpolate(this.collectionVariables[key]);
|
||||
return this._interpolate(this.runtimeVariables[key]);
|
||||
}
|
||||
|
||||
deleteVar(key) {
|
||||
delete this.collectionVariables[key];
|
||||
delete this.runtimeVariables[key];
|
||||
}
|
||||
|
||||
getRequestVar(key) {
|
||||
|
@ -2,7 +2,7 @@ const { interpolate } = require('@usebruno/common');
|
||||
|
||||
const interpolateString = (
|
||||
str,
|
||||
{ envVariables = {}, collectionVariables = {}, processEnvVars = {}, requestVariables = {} }
|
||||
{ envVariables = {}, runtimeVariables = {}, processEnvVars = {}, requestVariables = {} }
|
||||
) => {
|
||||
if (!str || !str.length || typeof str !== 'string') {
|
||||
return str;
|
||||
@ -11,7 +11,7 @@ const interpolateString = (
|
||||
const combinedVars = {
|
||||
...envVariables,
|
||||
...requestVariables,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
process: {
|
||||
env: {
|
||||
...processEnvVars
|
||||
|
@ -168,7 +168,7 @@ const evaluateRhsOperand = (rhsOperand, operator, context) => {
|
||||
|
||||
const interpolationContext = {
|
||||
requestVariables: context.bru.requestVariables,
|
||||
collectionVariables: context.bru.collectionVariables,
|
||||
runtimeVariables: context.bru.runtimeVariables,
|
||||
envVariables: context.bru.envVariables,
|
||||
processEnvVars: context.bru.processEnvVars
|
||||
};
|
||||
@ -204,14 +204,14 @@ const evaluateRhsOperand = (rhsOperand, operator, context) => {
|
||||
};
|
||||
|
||||
class AssertRuntime {
|
||||
runAssertions(assertions, request, response, envVariables, collectionVariables, processEnvVars) {
|
||||
runAssertions(assertions, request, response, envVariables, runtimeVariables, processEnvVars) {
|
||||
const requestVariables = request?.requestVariables || {};
|
||||
const enabledAssertions = _.filter(assertions, (a) => a.enabled);
|
||||
if (!enabledAssertions.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, undefined, requestVariables);
|
||||
const bru = new Bru(envVariables, runtimeVariables, processEnvVars, undefined, requestVariables);
|
||||
const req = new BrunoRequest(request);
|
||||
const res = createResponseParser(response);
|
||||
|
||||
@ -224,7 +224,7 @@ class AssertRuntime {
|
||||
const context = {
|
||||
...envVariables,
|
||||
...requestVariables,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
...processEnvVars,
|
||||
...bruContext
|
||||
};
|
||||
|
@ -38,14 +38,14 @@ class ScriptRuntime {
|
||||
script,
|
||||
request,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
) {
|
||||
const requestVariables = request?.requestVariables || {};
|
||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath, requestVariables);
|
||||
const bru = new Bru(envVariables, runtimeVariables, processEnvVars, collectionPath, requestVariables);
|
||||
const req = new BrunoRequest(request);
|
||||
const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
|
||||
const moduleWhitelist = get(scriptingConfig, 'moduleWhitelist', []);
|
||||
@ -126,7 +126,7 @@ class ScriptRuntime {
|
||||
return {
|
||||
request,
|
||||
envVariables: cleanJson(envVariables),
|
||||
collectionVariables: cleanJson(collectionVariables),
|
||||
runtimeVariables: cleanJson(runtimeVariables),
|
||||
nextRequestName: bru.nextRequest
|
||||
};
|
||||
}
|
||||
@ -136,14 +136,14 @@ class ScriptRuntime {
|
||||
request,
|
||||
response,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
) {
|
||||
const requestVariables = request?.requestVariables || {};
|
||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath, requestVariables);
|
||||
const bru = new Bru(envVariables, runtimeVariables, processEnvVars, collectionPath, requestVariables);
|
||||
const req = new BrunoRequest(request);
|
||||
const res = new BrunoResponse(response);
|
||||
const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
|
||||
@ -221,7 +221,7 @@ class ScriptRuntime {
|
||||
return {
|
||||
response,
|
||||
envVariables: cleanJson(envVariables),
|
||||
collectionVariables: cleanJson(collectionVariables),
|
||||
runtimeVariables: cleanJson(runtimeVariables),
|
||||
nextRequestName: bru.nextRequest
|
||||
};
|
||||
}
|
||||
|
@ -39,14 +39,14 @@ class TestRuntime {
|
||||
request,
|
||||
response,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
collectionPath,
|
||||
onConsoleLog,
|
||||
processEnvVars,
|
||||
scriptingConfig
|
||||
) {
|
||||
const requestVariables = request?.requestVariables || {};
|
||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, collectionPath, requestVariables);
|
||||
const bru = new Bru(envVariables, runtimeVariables, processEnvVars, collectionPath, requestVariables);
|
||||
const req = new BrunoRequest(request);
|
||||
const res = new BrunoResponse(response);
|
||||
const allowScriptFilesystemAccess = get(scriptingConfig, 'filesystemAccess.allow', false);
|
||||
@ -75,7 +75,7 @@ class TestRuntime {
|
||||
return {
|
||||
request,
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
results: __brunoTestResults.getResults()
|
||||
};
|
||||
}
|
||||
@ -146,7 +146,7 @@ class TestRuntime {
|
||||
return {
|
||||
request,
|
||||
envVariables: cleanJson(envVariables),
|
||||
collectionVariables: cleanJson(collectionVariables),
|
||||
runtimeVariables: cleanJson(runtimeVariables),
|
||||
results: cleanJson(__brunoTestResults.getResults())
|
||||
};
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ const BrunoRequest = require('../bruno-request');
|
||||
const { evaluateJsTemplateLiteral, evaluateJsExpression, createResponseParser } = require('../utils');
|
||||
|
||||
class VarsRuntime {
|
||||
runPreRequestVars(vars, request, envVariables, collectionVariables, collectionPath, processEnvVars) {
|
||||
runPreRequestVars(vars, request, envVariables, runtimeVariables, collectionPath, processEnvVars) {
|
||||
if (!request?.requestVariables) {
|
||||
request.requestVariables = {};
|
||||
}
|
||||
@ -13,7 +13,7 @@ class VarsRuntime {
|
||||
return;
|
||||
}
|
||||
|
||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars);
|
||||
const bru = new Bru(envVariables, runtimeVariables, processEnvVars);
|
||||
const req = new BrunoRequest(request);
|
||||
|
||||
const bruContext = {
|
||||
@ -23,7 +23,7 @@ class VarsRuntime {
|
||||
|
||||
const context = {
|
||||
...envVariables,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
...bruContext
|
||||
};
|
||||
|
||||
@ -33,14 +33,14 @@ class VarsRuntime {
|
||||
});
|
||||
}
|
||||
|
||||
runPostResponseVars(vars, request, response, envVariables, collectionVariables, collectionPath, processEnvVars) {
|
||||
runPostResponseVars(vars, request, response, envVariables, runtimeVariables, collectionPath, processEnvVars) {
|
||||
const requestVariables = request?.requestVariables || {};
|
||||
const enabledVars = _.filter(vars, (v) => v.enabled);
|
||||
if (!enabledVars.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bru = new Bru(envVariables, collectionVariables, processEnvVars, undefined, requestVariables);
|
||||
const bru = new Bru(envVariables, runtimeVariables, processEnvVars, undefined, requestVariables);
|
||||
const req = new BrunoRequest(request);
|
||||
const res = createResponseParser(response);
|
||||
|
||||
@ -52,7 +52,7 @@ class VarsRuntime {
|
||||
|
||||
const context = {
|
||||
...envVariables,
|
||||
...collectionVariables,
|
||||
...runtimeVariables,
|
||||
...bruContext
|
||||
};
|
||||
|
||||
@ -75,7 +75,7 @@ class VarsRuntime {
|
||||
|
||||
return {
|
||||
envVariables,
|
||||
collectionVariables,
|
||||
runtimeVariables,
|
||||
error
|
||||
};
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ describe('runtime', () => {
|
||||
|
||||
const runtime = new ScriptRuntime();
|
||||
const result = await runtime.runRequestScript(script, { ...baseRequest }, {}, {}, '.', null, process.env);
|
||||
expect(result.collectionVariables.validation).toBeTruthy();
|
||||
expect(result.runtimeVariables.validation).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@ -171,7 +171,7 @@ describe('runtime', () => {
|
||||
null,
|
||||
process.env
|
||||
);
|
||||
expect(result.collectionVariables.validation).toBeTruthy();
|
||||
expect(result.runtimeVariables.validation).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -309,7 +309,7 @@ const collectionSchema = Yup.object({
|
||||
runnerResult: Yup.object({
|
||||
items: Yup.array()
|
||||
}),
|
||||
collectionVariables: Yup.object(),
|
||||
runtimeVariables: Yup.object(),
|
||||
brunoConfig: Yup.object(),
|
||||
root: folderRootSchema
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user