api-client/functions/preRequest.js

21 lines
671 B
JavaScript
Raw Normal View History

2019-10-30 01:28:44 +00:00
export default function getEnvironmentVariablesFromScript(script) {
let _variables = {};
// 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: {
2019-11-28 15:11:52 +00:00
set: (key, value) => (_variables[key] = value)
2019-10-30 01:28:44 +00:00
},
env: {
2019-11-28 15:11:52 +00:00
set: (key, value) => (_variables[key] = value)
}
2019-10-30 01:28:44 +00:00
// globals that the script is allowed to have access to.
};
// run pre-request script within this function so that it has access to the pw object.
2019-11-28 15:11:52 +00:00
new Function("pw", script)(pw);
2019-10-30 01:28:44 +00:00
return _variables;
}