api-client/helpers/preRequest.js

23 lines
722 B
JavaScript
Raw Normal View History

2019-10-30 01:28:44 +00:00
export default function getEnvironmentVariablesFromScript(script) {
2020-02-24 18:44:50 +00:00
let _variables = {}
2019-10-30 01:28:44 +00:00
try {
// the pw object is the proxy by which pre-request scripts can pass variables to the request.
// for security and control purposes, this is the only way a pre-request script should modify variables.
let pw = {
environment: {
set: (key, value) => (_variables[key] = value),
},
env: {
set: (key, value) => (_variables[key] = value),
},
// globals that the script is allowed to have access to.
}
2019-10-30 01:28:44 +00:00
// run pre-request script within this function so that it has access to the pw object.
new Function("pw", script)(pw)
} catch (_e) {}
2019-10-30 01:28:44 +00:00
2020-02-24 18:44:50 +00:00
return _variables
2019-10-30 01:28:44 +00:00
}