I have a static resource to reuse javascript between my lightning components. I'd like the code to use specific credentials for an api in a sandbox, and another in production. I plan to use an apex controller function in my component to determine if it's being called in production first, the instantiate my static resource with with a returned value.
This is a sample of what my static resource looks like. It's similar to what can be found in the docs.
window.Utility = (function (isSandbox) {
let name;
let transactionKey;
let endPoint;
if (isSandbox) {
name = "abc";
transactionKey = "123";
endPoint = "https://test.net/";
} else {
name = "def";
transactionKey = "456";
endPoint = "https://api.net/";
}
return { // public api
getData: function (recordId) {
// do stuff
}
};
}());
When I call this code
Utility(true).getData('5000v000003r3tEAAQ');
It doesn't work. I have a ton of functions in my static resource, and it would be ideal to set the class variables every time I call a function vs having to pass them via function.