From e38ee91bab6a756184dfb05d46976fc5f378400f Mon Sep 17 00:00:00 2001 From: David Patrick Date: Thu, 21 Jan 2021 12:14:03 -0800 Subject: [PATCH] Additional options on getByEmail (#577) --- src/management/UsersManager.js | 14 ++++++++++---- src/management/index.js | 7 +++++-- test/management/users.tests.js | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/management/UsersManager.js b/src/management/UsersManager.js index a6647c32c..a9c18ff0f 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..1dfac641d 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() {