[JS] Extract client builder
[JS]  Fix router and minor refactoring