statsig-io / node-js-server-sdk

Statsig's SDK for server-side Node.js applications.
ISC License
20 stars 15 forks source link

Add normalizing of user user object in getClientInitializeResponse #8

Closed eliecer2323 closed 2 years ago

eliecer2323 commented 2 years ago

The getClientInitializeResponse function of the statsig-node SDK actually doesn’t evaluate the environment tier value, doing some debugging it was found that it isn't setting that value it is getting undefined when trying to evaluate it and by conclusion a false boolean in the result.

There is already a function called normalizeUser for setting the environment to the user so just using this one the problem can be solved.

I hope this explanation can help to speed up a new release with the adjustment.

Currently: StatsigServer.getClientInitializeResponse -> Evaluator.getClientInitializeResponse -> eval -> evalRule -> evalCondition -> getFromEnvironment -> undefined statsigEnvironment

Solution: StatsigServer.getClientInitializeResponse -> normalizeUser -> Evaluator.getClientInitializeResponse -> eval -> evalRule -> evalCondition -> getFromEnvironment -> existing statsigEnvironment

tore-statsig commented 2 years ago

We've decided to move forward with this behavior, but only if the user passed in does not have statsigEnvironment on it, in order to support a likely rare case where the environment on the client does not match the environment on the server.

Ill commit this separately - thanks for bringing this to our attention!