From 11b07db12c3441ba88b234cf3dc0f9d7380ad836 Mon Sep 17 00:00:00 2001 From: James George <25279263+jamesgeorge007@users.noreply.github.com> Date: Mon, 6 Oct 2025 16:45:35 +0530 Subject: [PATCH] fix(js-sandbox): resolve errors with `pw.env` namespace in legacy sandbox (#5433) --- .../src/types/post-request.d.ts | 4 ++- .../hoppscotch-js-sandbox/src/utils/shared.ts | 33 +++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/packages/hoppscotch-common/src/types/post-request.d.ts b/packages/hoppscotch-common/src/types/post-request.d.ts index 1b5eafca..c8fd9eea 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 ac738d37..d95a3ff4 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, }