preRequest.ts 759 B

1234567891011121314151617181920212223242526272829
  1. import { runPreRequestScript } from "@hoppscotch/js-sandbox"
  2. import {
  3. getCurrentEnvironment,
  4. getGlobalVariables,
  5. } from "~/newstore/environments"
  6. export const getCombinedEnvVariables = () => {
  7. const variables: { key: string; value: string }[] = [...getGlobalVariables()]
  8. for (const variable of getCurrentEnvironment().variables) {
  9. const index = variables.findIndex((v) => variable.key === v.key)
  10. if (index === -1) {
  11. variables.push({
  12. key: variable.key,
  13. value: variable.value,
  14. })
  15. } else {
  16. variables[index].value = variable.value
  17. }
  18. }
  19. return variables
  20. }
  21. export const getFinalEnvsFromPreRequest = (
  22. script: string,
  23. envs: { key: string; value: string }[]
  24. ) => runPreRequestScript(script, envs)