feat: fix issue with the pre-request envs
This commit is contained in:
@@ -307,7 +307,8 @@ watch(loading, () => {
|
|||||||
const newSendRequest = async () => {
|
const newSendRequest = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
||||||
const streamResult = await runRESTRequest$()
|
// Double calling is because the function returns a TaskEither than should be executed
|
||||||
|
const streamResult = await runRESTRequest$()()
|
||||||
|
|
||||||
// TODO: What if stream fetching failed (script execution errors ?) (isLeft)
|
// TODO: What if stream fetching failed (script execution errors ?) (isLeft)
|
||||||
if (isRight(streamResult)) {
|
if (isRight(streamResult)) {
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { chain, right, TaskEither } from "fp-ts/lib/TaskEither"
|
|||||||
import { pipe } from "fp-ts/lib/function"
|
import { pipe } from "fp-ts/lib/function"
|
||||||
import { runTestScript, TestDescriptor } from "@hoppscotch/js-sandbox"
|
import { runTestScript, TestDescriptor } from "@hoppscotch/js-sandbox"
|
||||||
import { isRight } from "fp-ts/lib/Either"
|
import { isRight } from "fp-ts/lib/Either"
|
||||||
import { getFinalEnvsFromPreRequest } from "./preRequest"
|
import {
|
||||||
|
getCombinedEnvVariables,
|
||||||
|
getFinalEnvsFromPreRequest,
|
||||||
|
} from "./preRequest"
|
||||||
import { getEffectiveRESTRequest } from "./utils/EffectiveURL"
|
import { getEffectiveRESTRequest } from "./utils/EffectiveURL"
|
||||||
import { HoppRESTResponse } from "./types/HoppRESTResponse"
|
import { HoppRESTResponse } from "./types/HoppRESTResponse"
|
||||||
import { createRESTNetworkRequestStream } from "./network"
|
import { createRESTNetworkRequestStream } from "./network"
|
||||||
@@ -25,13 +28,16 @@ const getTestableBody = (res: HoppRESTResponse & { type: "success" }) => {
|
|||||||
return JSON.parse(rawBody)
|
return JSON.parse(rawBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const runRESTRequest$: TaskEither<
|
export const runRESTRequest$ = (): TaskEither<
|
||||||
string,
|
string,
|
||||||
Observable<HoppRESTResponse>
|
Observable<HoppRESTResponse>
|
||||||
> = pipe(
|
> =>
|
||||||
getFinalEnvsFromPreRequest(),
|
pipe(
|
||||||
|
getFinalEnvsFromPreRequest(
|
||||||
|
getRESTRequest().preRequestScript,
|
||||||
|
getCombinedEnvVariables()
|
||||||
|
),
|
||||||
chain((envs) => {
|
chain((envs) => {
|
||||||
console.log(envs)
|
|
||||||
const effectiveRequest = getEffectiveRESTRequest(getRESTRequest(), {
|
const effectiveRequest = getEffectiveRESTRequest(getRESTRequest(), {
|
||||||
name: "Env",
|
name: "Env",
|
||||||
variables: envs,
|
variables: envs,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import {
|
|||||||
getCurrentEnvironment,
|
getCurrentEnvironment,
|
||||||
getGlobalVariables,
|
getGlobalVariables,
|
||||||
} from "~/newstore/environments"
|
} from "~/newstore/environments"
|
||||||
import { getRESTRequest } from "~/newstore/RESTSession"
|
|
||||||
|
|
||||||
export const getCombinedEnvVariables = () => {
|
export const getCombinedEnvVariables = () => {
|
||||||
const variables: { key: string; value: string }[] = [...getGlobalVariables()]
|
const variables: { key: string; value: string }[] = [...getGlobalVariables()]
|
||||||
@@ -24,8 +23,7 @@ export const getCombinedEnvVariables = () => {
|
|||||||
return variables
|
return variables
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getFinalEnvsFromPreRequest = () =>
|
export const getFinalEnvsFromPreRequest = (
|
||||||
runPreRequestScript(
|
script: string,
|
||||||
getRESTRequest().preRequestScript,
|
envs: { key: string; value: string }[]
|
||||||
getCombinedEnvVariables()
|
) => runPreRequestScript(script, envs)
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user