preRequest.ts (hoppscotch-2.2.1) | : | preRequest.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
import { runPreRequestScript } from "@hoppscotch/js-sandbox" | import { runPreRequestScript } from "@hoppscotch/js-sandbox" | |||
import { Environment } from "@hoppscotch/data" | ||||
import { cloneDeep } from "lodash-es" | ||||
import { | import { | |||
getCurrentEnvironment, | getCurrentEnvironment, | |||
getGlobalVariables, | getGlobalVariables, | |||
} from "~/newstore/environments" | } from "~/newstore/environments" | |||
export const getCombinedEnvVariables = () => { | export const getCombinedEnvVariables = () => ({ | |||
const variables: { key: string; value: string }[] = [...getGlobalVariables()] | global: cloneDeep(getGlobalVariables()), | |||
selected: cloneDeep(getCurrentEnvironment().variables), | ||||
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 getFinalEnvsFromPreRequest = ( | export const getFinalEnvsFromPreRequest = ( | |||
script: string, | script: string, | |||
envs: { key: string; value: string }[] | envs: { | |||
global: Environment["variables"] | ||||
selected: Environment["variables"] | ||||
} | ||||
) => runPreRequestScript(script, envs) | ) => runPreRequestScript(script, envs) | |||
End of changes. 3 change blocks. | ||||
19 lines changed or deleted | 10 lines changed or added |