Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix(js-sandbox): resolve errors with `pw.env` namespace in legacy sandbox (#5433)

James George11b07db12c34
diff --git a/packages/hoppscotch-common/src/types/post-request.d.ts b/packages/hoppscotch-common/src/types/post-request.d.ts
index 1b5eafcad..c8fd9eea9 100644
--- a/packages/hoppscotch-common/src/types/post-request.d.ts
+++ b/packages/hoppscotch-common/src/types/post-request.d.ts
@@ -256,9 +256,11 @@ declare namespace pw {
headers: HoppRESTResponseHeader[]
}>
namespace env {
+ function set(key: string, value: string): void
+ function unset(key: string): void
function get(key: string): string
function getResolve(key: string): string
- function resolve(key: string): string
+ function resolve(value: string): string
}
}
diff --git a/packages/hoppscotch-js-sandbox/src/utils/shared.ts b/packages/hoppscotch-js-sandbox/src/utils/shared.ts
index ac738d371..d95a3ff43 100644
--- a/packages/hoppscotch-js-sandbox/src/utils/shared.ts
+++ b/packages/hoppscotch-js-sandbox/src/utils/shared.ts
@@ -158,21 +158,24 @@ export function getSharedEnvMethods(
}
/**
- * Legacy sandbox version - Returns flat methods for `pw` namespace only
+ * Legacy sandbox version - Methods pre-wrapped in `env` for direct `pw` namespace assignment
+ * (Experimental sandbox powered by `faraday-cage` handles this wrapping via bootstrap code)
*/
export function getSharedEnvMethods(
envs: TestResult["envs"],
isHoppNamespace?: false
): {
methods: {
- get: (key: string, options?: EnvAPIOptions) => string | null | undefined
- getResolve: (
- key: string,
- options?: EnvAPIOptions
- ) => string | null | undefined
- set: (key: string, value: string, options?: EnvAPIOptions) => void
- unset: (key: string, options?: EnvAPIOptions) => void
- resolve: (key: string) => string
+ env: {
+ get: (key: string, options?: EnvAPIOptions) => string | null | undefined
+ getResolve: (
+ key: string,
+ options?: EnvAPIOptions
+ ) => string | null | undefined
+ set: (key: string, value: string, options?: EnvAPIOptions) => void
+ unset: (key: string, options?: EnvAPIOptions) => void
+ resolve: (key: string) => string
+ }
}
updatedEnvs: TestResult["envs"]
}
@@ -380,11 +383,13 @@ export function getSharedEnvMethods(
// Legacy scripting sandbox (Only `pw` namespace)
return {
methods: {
- get: envGetFn,
- getResolve: envGetResolveFn,
- set: envSetFn,
- unset: envUnsetFn,
- resolve: envResolveFn,
+ env: {
+ get: envGetFn,
+ getResolve: envGetResolveFn,
+ set: envSetFn,
+ unset: envUnsetFn,
+ resolve: envResolveFn,
+ },
},
updatedEnvs,
}