feat: introduce APIs to update envs from tests and recursive resolution
This commit is contained in:
@@ -1,29 +1,19 @@
|
||||
import { runPreRequestScript } from "@hoppscotch/js-sandbox"
|
||||
import { Environment } from "@hoppscotch/data"
|
||||
import {
|
||||
getCurrentEnvironment,
|
||||
getGlobalVariables,
|
||||
} from "~/newstore/environments"
|
||||
|
||||
export const getCombinedEnvVariables = () => {
|
||||
const variables: { key: string; value: string }[] = [...getGlobalVariables()]
|
||||
|
||||
for (const variable of getCurrentEnvironment().variables) {
|
||||
const index = variables.findIndex((v) => variable.key === v.key)
|
||||
|
||||
if (index === -1) {
|
||||
variables.push({
|
||||
key: variable.key,
|
||||
value: variable.value,
|
||||
})
|
||||
} else {
|
||||
variables[index].value = variable.value
|
||||
}
|
||||
}
|
||||
|
||||
return variables
|
||||
}
|
||||
export const getCombinedEnvVariables = () => ({
|
||||
global: getGlobalVariables(),
|
||||
selected: getCurrentEnvironment().variables,
|
||||
})
|
||||
|
||||
export const getFinalEnvsFromPreRequest = (
|
||||
script: string,
|
||||
envs: { key: string; value: string }[]
|
||||
envs: {
|
||||
global: Environment["variables"]
|
||||
selected: Environment["variables"]
|
||||
}
|
||||
) => runPreRequestScript(script, envs)
|
||||
|
||||
Reference in New Issue
Block a user