Files
hoppscotch/packages/hoppscotch-app/helpers/preRequest.ts
2021-09-25 01:09:48 +05:30

32 lines
817 B
TypeScript

import { runPreRequestScript } from "@hoppscotch/js-sandbox"
import {
getCurrentEnvironment,
getGlobalVariables,
} from "~/newstore/environments"
import { getRESTRequest } from "~/newstore/RESTSession"
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 getFinalEnvsFromPreRequest = () =>
runPreRequestScript(
getRESTRequest().preRequestScript,
getCombinedEnvVariables()
)