Skip to content

Commit e1bf485

Browse files
committed
compute post response vars and add them to env variables
1 parent ff50abb commit e1bf485

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

src/components/molecules/flow/graph/Graph.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// assumption is that apis are giving json as output
22

3+
import { cloneDeep } from 'lodash';
34
import useCanvasStore from 'stores/CanvasStore';
45
import useCollectionStore from 'stores/CollectionStore';
56
import { useTabStore } from 'stores/TabStore';
@@ -9,6 +10,10 @@ import { computeRequestNode } from './compute/requestnode';
910

1011
class Graph {
1112
constructor(nodes, edges, collectionId, onGraphComplete) {
13+
const activeEnv = useCollectionStore
14+
.getState()
15+
.collections.find((c) => c.id === collectionId)
16+
?.environments.find((e) => e.name === useTabStore.getState().selectedEnv);
1217
this.nodes = nodes;
1318
this.edges = edges;
1419
this.onGraphComplete = onGraphComplete;
@@ -17,10 +22,7 @@ class Graph {
1722
this.startTime = Date.now();
1823
this.graphRunNodeOutput = {};
1924
this.auth = undefined;
20-
this.env = useCollectionStore
21-
.getState()
22-
.collections.find((c) => c.id === collectionId)
23-
?.environments.find((e) => e.name === useTabStore.getState().selectedEnv);
25+
this.envVariables = activeEnv ? cloneDeep(activeEnv.variables) : undefined;
2426
}
2527

2628
#checkTimeout() {
@@ -95,12 +97,19 @@ class Graph {
9597
}
9698

9799
if (node.type === 'authNode') {
98-
this.auth = node.data.type ? computeAuthNode(node.data, this.env) : undefined;
100+
this.auth = node.data.type ? computeAuthNode(node.data, this.envVariables) : undefined;
99101
result = ['Success', node, prevNodeOutput];
100102
}
101103

102104
if (node.type === 'requestNode') {
103-
result = await computeRequestNode(node, prevNodeOutputData, this.env, this.auth, this.logs);
105+
result = await computeRequestNode(node, prevNodeOutputData, this.envVariables, this.auth, this.logs);
106+
// add post response variables if any
107+
if (result[3]) {
108+
this.envVariables = {
109+
...this.envVariables,
110+
...result[3],
111+
};
112+
}
104113
}
105114

106115
if (this.#checkTimeout()) {

src/components/molecules/flow/graph/compute/authnode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { computeVariables } from './utils';
22

3-
export const computeAuthNode = (auth, env) => {
3+
export const computeAuthNode = (auth, envVariables) => {
44
if (auth.type === 'basic-auth') {
5-
auth.username = computeVariables(auth.username, env?.variables);
6-
auth.password = computeVariables(auth.password, env?.variables);
5+
auth.username = computeVariables(auth.username, envVariables);
6+
auth.password = computeVariables(auth.password, envVariables);
77

88
return auth;
99
} else if (auth.type === 'no-auth') {

src/components/molecules/flow/graph/compute/requestnode.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ const formulateRequest = (node, finalUrl, variablesDict, auth, logs) => {
4848
return options;
4949
};
5050

51-
export const computeRequestNode = async (node, prevNodeOutputData, env, auth, logs) => {
51+
export const computeRequestNode = async (node, prevNodeOutputData, envVariables, auth, logs) => {
5252
// step1 evaluate variables of this node
5353
const evalVariables = computeNodeVariables(node.data.preReqVars, prevNodeOutputData);
5454

5555
const variablesDict = {
56-
...env?.variables,
56+
...envVariables,
5757
...evalVariables,
5858
};
5959

@@ -76,6 +76,10 @@ export const computeRequestNode = async (node, prevNodeOutputData, env, auth, lo
7676
} else {
7777
logs.push(`Request successful: ${JSON.stringify(res)}`);
7878
console.debug('Response: ', JSON.stringify(res));
79+
if (node.data.postRespVars) {
80+
const evalPostRespVars = computeNodeVariables(node.data.postRespVars, res.data);
81+
return ['Success', node, res, evalPostRespVars];
82+
}
7983
return ['Success', node, res];
8084
}
8185
};

0 commit comments

Comments
 (0)