diff --git a/lib/querystring.ts b/lib/querystring.ts index 8053ece04..c3cd42950 100644 --- a/lib/querystring.ts +++ b/lib/querystring.ts @@ -1,29 +1,14 @@ -/* eslint-disable prettier/prettier, arrow-body-style */ - /** - * Stringify query params, Watson-style - * - * Why? The server that processes auth tokens currently only accepts the *exact* string, even if it's invalid for a URL. - * Properly url-encoding percent characters causes it to reject the token - * So, this is a custom qs.stringify function that properly encodes everything except watson-token, passing it along verbatim + * Lightweight implementation for stringify-ing query params * * @param {object} queryParams * @return {String} */ -const stringify = (queryParams: Object): string => { - return Object.keys(queryParams) - .map((key) => { - return ( - `${key - }=${ - key === 'watson-token' - ? queryParams[key] - : encodeURIComponent(queryParams[key])}` - ); // the server chokes if the token is correctly url-encoded - }) +const stringify = (queryParams: Object): string => + Object.keys(queryParams) + .map((key) => `${key}=${encodeURIComponent(queryParams[key])}`) .join('&'); -}; export default { - stringify + stringify, }; diff --git a/scripts/jsdoc/template/tmpl/layout.tmpl b/scripts/jsdoc/template/tmpl/layout.tmpl index 31d0759f9..fd45a0aad 100644 --- a/scripts/jsdoc/template/tmpl/layout.tmpl +++ b/scripts/jsdoc/template/tmpl/layout.tmpl @@ -2,7 +2,7 @@ - <?js= title ?> | Watson Developer Cloud Node.js SDK Documentation + <?js= title ?> | Node SDK Core Documentation diff --git a/test/unit/querystring.test.js b/test/unit/querystring.test.js new file mode 100644 index 000000000..d51aab2af --- /dev/null +++ b/test/unit/querystring.test.js @@ -0,0 +1,8 @@ +const { stringify } = require('../../dist/lib/querystring').default; + +describe('querystring', () => { + it('should convert params to query string format', () => { + const params = { foo: 'bar', baz: ['qux', 'quux'], corge: '' }; + expect(stringify(params)).toBe('foo=bar&baz=qux%2Cquux&corge='); + }); +});