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, }