diff --git a/src/management/UsersManager.js b/src/management/UsersManager.js index a6647c32c..b13929f25 100644 --- a/src/management/UsersManager.js +++ b/src/management/UsersManager.js @@ -1,6 +1,7 @@ var ArgumentError = require('rest-facade').ArgumentError; var Auth0RestClient = require('../Auth0RestClient'); var RetryRestClient = require('../RetryRestClient'); +var sanitizeArguments = require('../utils').sanitizeArguments; /** * Simple facade for consuming a REST API endpoint. @@ -238,13 +239,18 @@ UsersManager.prototype.getAll = function(params) { * console.log(users); * }); * - * @param {String} [email] Email address of user(s) to find - * @param {Function} [cb] Callback function. + * @param {String} [email] Email address of user(s) to find + * @param {Object} [options] Additional options to pass to the endpoint + * @param {string} [options.fields] Comma-separated list of fields to include or exclude in the result + * @param {boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true. + * @param {Function} [cb] Callback function. * * @return {Promise|undefined} */ -UsersManager.prototype.getByEmail = function(email, callback) { - return this.usersByEmail.getAll({ email }, callback); +UsersManager.prototype.getByEmail = function(email, options, cb) { + var { options, cb } = sanitizeArguments(options, cb); + + return this.usersByEmail.getAll({ email, ...options }, cb); }; /** diff --git a/src/management/index.js b/src/management/index.js index 092ec8ac7..43126390b 100644 --- a/src/management/index.js +++ b/src/management/index.js @@ -1019,8 +1019,11 @@ utils.wrapPropertyMethod(ManagementClient, 'getUsers', 'users.getAll'); * console.log(users); * }); * - * @param {String} [email] Email Address of users to locate - * @param {Function} [cb] Callback function. + * @param {String} [email] Email address of user(s) to find + * @param {Object} [options] Additional options to pass to the endpoint + * @param {string} [options.fields] Comma-separated list of fields to include or exclude in the result + * @param {boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true. + * @param {Function} [cb] Callback function. * * @return {Promise|undefined} */ diff --git a/test/management/users.tests.js b/test/management/users.tests.js index 16714a6ae..4c3d2b94d 100644 --- a/test/management/users.tests.js +++ b/test/management/users.tests.js @@ -259,6 +259,30 @@ describe('UsersManager', function() { done(); }); }); + + it('should pass additional options into the query string', function(done) { + nock.cleanAll(); + + var additionalOptions = { + fields: 'user_id, email, email_verified', + include_fields: true + }; + var params = { + email: 'email@example.com', + ...additionalOptions + }; + + var request = nock(API_URL) + .get('/users-by-email') + .query(params) + .reply(200); + + this.users.getByEmail(params.email, additionalOptions).then(function() { + expect(request.isDone()).to.be.true; + + done(); + }); + }); }); describe('#get', function() {