Separate client lib into smaller modules

PR to track work on merging parts of the codebase.

I think it would be nice to see if we can't have parts of the codebase be re-used better. This first commit just separates out the single `client.js` file into logical pieces.

My goal is to eventually re-use as many of the tests as possible as well. Right now there is a divide between the node tests and client tests (just like in the code).