Skip to content

Commit

Permalink
feat/rename collectionVariables variable name to runtimeVariables (us…
Browse files Browse the repository at this point in the history
…ebruno#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 <[email protected]>
  • Loading branch information
lohxt1 and helloanoop authored Jul 17, 2024
1 parent e60aaf2 commit ab9bcbe
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 132 deletions.
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const GenerateCodeItem = ({ collection, item, onClose }) => {
const interpolatedUrl = interpolateUrl({
url: requestUrl,
envVars,
collectionVariables: collection.collectionVariables,
runtimeVariables: collection.runtimeVariables,
processEnvVars: collection.processEnvVariables
});

Expand Down
22 changes: 11 additions & 11 deletions packages/bruno-app/src/components/VariablesEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ 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
}));

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>
)}
</>
);
Expand All @@ -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>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -314,7 +314,7 @@ export const runCollectionFolder = (collectionUid, folderUid, recursive) => (dis
folder,
collectionCopy,
environment,
collectionCopy.collectionVariables,
collectionCopy.runtimeVariables,
recursive
)
.then(resolve)
Expand Down Expand Up @@ -1036,7 +1036,7 @@ export const openCollectionEvent = (uid, pathname, brunoConfig) => (dispatch, ge
name: brunoConfig.name,
pathname: pathname,
items: [],
collectionVariables: {},
runtimeVariables: {},
brunoConfig: brunoConfig
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -230,7 +230,7 @@ export const collectionsSlice = createSlice({
});
}

collection.collectionVariables = collectionVariables;
collection.runtimeVariables = runtimeVariables;
}
},
processEnvUpdateEvent: (state, action) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-app/src/utils/collections/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ export const getAllVariables = (collection, item) => {
return {
...environmentVariables,
...requestVariables,
...collection.collectionVariables,
...collection.runtimeVariables,
pathParams: {
...pathParams
},
Expand Down
12 changes: 6 additions & 6 deletions packages/bruno-app/src/utils/network/index.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-app/src/utils/url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/bruno-app/src/utils/url/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/bruno-cli/src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ const handler = async function (argv) {
recursive = true;
}

const collectionVariables = {};
const runtimeVariables = {};
let envVars = {};

if (env) {
Expand Down Expand Up @@ -462,7 +462,7 @@ const handler = async function (argv) {
bruFilepath,
bruJson,
collectionPath,
collectionVariables,
runtimeVariables,
envVars,
processEnvVars,
brunoConfig,
Expand Down
8 changes: 4 additions & 4 deletions packages/bruno-cli/src/runner/interpolate-string.js
Original file line number Diff line number Diff line change
@@ -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) : {};
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/bruno-cli/src/runner/interpolate-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions packages/bruno-cli/src/runner/run-single-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const runSingleRequest = async function (
filename,
bruJson,
collectionPath,
collectionVariables,
runtimeVariables,
envVariables,
processEnvVars,
brunoConfig,
Expand Down Expand Up @@ -62,7 +62,7 @@ const runSingleRequest = async function (
preRequestVars,
request,
envVariables,
collectionVariables,
runtimeVariables,
collectionPath,
processEnvVars
);
Expand All @@ -79,7 +79,7 @@ const runSingleRequest = async function (
decomment(requestScriptFile),
request,
envVariables,
collectionVariables,
runtimeVariables,
collectionPath,
null,
processEnvVars,
Expand All @@ -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}`;
Expand Down Expand Up @@ -120,7 +120,7 @@ const runSingleRequest = async function (

const interpolationOptions = {
envVars: envVariables,
collectionVariables,
runtimeVariables,
processEnvVars
};

Expand Down Expand Up @@ -282,7 +282,7 @@ const runSingleRequest = async function (
request,
response,
envVariables,
collectionVariables,
runtimeVariables,
collectionPath,
processEnvVars
);
Expand All @@ -300,7 +300,7 @@ const runSingleRequest = async function (
request,
response,
envVariables,
collectionVariables,
runtimeVariables,
collectionPath,
null,
processEnvVars,
Expand All @@ -321,7 +321,7 @@ const runSingleRequest = async function (
request,
response,
envVariables,
collectionVariables,
runtimeVariables,
processEnvVars
);

Expand All @@ -345,7 +345,7 @@ const runSingleRequest = async function (
request,
response,
envVariables,
collectionVariables,
runtimeVariables,
collectionPath,
null,
processEnvVars,
Expand Down
Loading

0 comments on commit ab9bcbe

Please sign in to comment.