Skip to content

Commit 11b07db

Browse files
fix(js-sandbox): resolve errors with pw.env namespace in legacy sandbox (hoppscotch#5433)
1 parent 6bbfb9b commit 11b07db

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

packages/hoppscotch-common/src/types/post-request.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,11 @@ declare namespace pw {
256256
headers: HoppRESTResponseHeader[]
257257
}>
258258
namespace env {
259+
function set(key: string, value: string): void
260+
function unset(key: string): void
259261
function get(key: string): string
260262
function getResolve(key: string): string
261-
function resolve(key: string): string
263+
function resolve(value: string): string
262264
}
263265
}
264266

packages/hoppscotch-js-sandbox/src/utils/shared.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,24 @@ export function getSharedEnvMethods(
158158
}
159159

160160
/**
161-
* Legacy sandbox version - Returns flat methods for `pw` namespace only
161+
* Legacy sandbox version - Methods pre-wrapped in `env` for direct `pw` namespace assignment
162+
* (Experimental sandbox powered by `faraday-cage` handles this wrapping via bootstrap code)
162163
*/
163164
export function getSharedEnvMethods(
164165
envs: TestResult["envs"],
165166
isHoppNamespace?: false
166167
): {
167168
methods: {
168-
get: (key: string, options?: EnvAPIOptions) => string | null | undefined
169-
getResolve: (
170-
key: string,
171-
options?: EnvAPIOptions
172-
) => string | null | undefined
173-
set: (key: string, value: string, options?: EnvAPIOptions) => void
174-
unset: (key: string, options?: EnvAPIOptions) => void
175-
resolve: (key: string) => string
169+
env: {
170+
get: (key: string, options?: EnvAPIOptions) => string | null | undefined
171+
getResolve: (
172+
key: string,
173+
options?: EnvAPIOptions
174+
) => string | null | undefined
175+
set: (key: string, value: string, options?: EnvAPIOptions) => void
176+
unset: (key: string, options?: EnvAPIOptions) => void
177+
resolve: (key: string) => string
178+
}
176179
}
177180
updatedEnvs: TestResult["envs"]
178181
}
@@ -380,11 +383,13 @@ export function getSharedEnvMethods(
380383
// Legacy scripting sandbox (Only `pw` namespace)
381384
return {
382385
methods: {
383-
get: envGetFn,
384-
getResolve: envGetResolveFn,
385-
set: envSetFn,
386-
unset: envUnsetFn,
387-
resolve: envResolveFn,
386+
env: {
387+
get: envGetFn,
388+
getResolve: envGetResolveFn,
389+
set: envSetFn,
390+
unset: envUnsetFn,
391+
resolve: envResolveFn,
392+
},
388393
},
389394
updatedEnvs,
390395
}

0 commit comments

Comments
 (0)