From 4e7e179854c00c0cf513221c788e96ff8c43c889 Mon Sep 17 00:00:00 2001 From: adamjmcgrath Date: Thu, 22 Sep 2022 12:25:44 +0100 Subject: [PATCH] Add BaseManager class --- src/management/ActionsManager.js | 85 +++------------- src/management/AttackProtectionManager.js | 45 ++------ src/management/BaseManager.js | 39 +++++++ src/management/BlacklistedTokensManager.js | 36 +------ src/management/BrandingManager.js | 45 ++------ src/management/ClientGrantsManager.js | 36 +------ src/management/ClientsManager.js | 42 +------- src/management/ConnectionsManager.js | 48 ++------- src/management/CustomDomainsManager.js | 42 +------- src/management/DeviceCredentialsManager.js | 30 +----- src/management/EmailProviderManager.js | 36 +------ src/management/EmailTemplatesManager.js | 31 +----- src/management/GrantsManager.js | 36 +------ src/management/GuardianManager.js | 99 +++--------------- src/management/HooksManager.js | 41 +------- src/management/JobsManager.js | 44 ++------ src/management/LogStreamsManager.js | 35 +------ src/management/LogsManager.js | 35 +------ src/management/MigrationsManager.js | 31 +----- src/management/OrganizationsManager.js | 79 +++------------ src/management/PromptsManager.js | 40 +------- src/management/ResourceServersManager.js | 35 +------ src/management/RolesManager.js | 48 ++------- src/management/RulesConfigsManager.js | 35 +------ src/management/RulesManager.js | 35 +------ src/management/StatsManager.js | 31 +----- src/management/TenantManager.js | 31 +----- src/management/TicketsManager.js | 31 +----- src/management/UserBlocksManager.js | 40 +------- src/management/UsersManager.js | 107 +++----------------- test/management/actions.tests.js | 2 +- test/management/blacklisted-tokens.tests.js | 2 +- test/management/client-grants.tests.js | 2 +- test/management/client.tests.js | 2 +- test/management/connections.tests.js | 2 +- test/management/email-provider.tests.js | 2 +- test/management/email-templates.tests.js | 4 +- test/management/grants.tests.js | 2 +- test/management/jobs.tests.js | 2 +- test/management/log-streams.tests.js | 2 +- test/management/logs.tests.js | 2 +- test/management/resource-servers.tests.js | 2 +- 42 files changed, 224 insertions(+), 1150 deletions(-) create mode 100644 src/management/BaseManager.js diff --git a/src/management/ActionsManager.js b/src/management/ActionsManager.js index 0d80f8022..dd5053912 100644 --- a/src/management/ActionsManager.js +++ b/src/management/ActionsManager.js @@ -1,13 +1,11 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * {@link https://auth0.com/docs/api/v2#!/Actions/get_actions Actions} provide a way to extend * Auth0 flows with custom logic. * See the {@link https://auth0.com/docs/actions Actions documentation} for more information. */ -class ActionsManager { +class ActionsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -15,28 +13,7 @@ class ActionsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -44,61 +21,23 @@ class ActionsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/actions/actions/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/actions/actions/:id'); - const actionsDeployRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/actions/:id/deploy`, - clientOptions, - options.tokenProvider - ); - this.actionsDeploy = new RetryRestClient(actionsDeployRestClient, options.retry); + this.actionsDeploy = this._getRestClient('/actions/actions/:id/deploy'); - const actionsTestRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/actions/:id/test`, - clientOptions, - options.tokenProvider - ); - this.actionsTest = new RetryRestClient(actionsTestRestClient, options.retry); + this.actionsTest = this._getRestClient('/actions/actions/:id/test'); - const triggersRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/triggers/:trigger_id`, - clientOptions, - options.tokenProvider - ); - this.triggers = new RetryRestClient(triggersRestClient, options.retry); + this.triggers = this._getRestClient('/actions/triggers/:trigger_id'); - const triggerBindingsRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/triggers/:trigger_id/bindings`, - clientOptions, - options.tokenProvider - ); - this.triggerBindings = new RetryRestClient(triggerBindingsRestClient, options.retry); + this.triggerBindings = this._getRestClient('/actions/triggers/:trigger_id/bindings'); - const executionsRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/executions/:execution_id`, - clientOptions, - options.tokenProvider - ); - this.executions = new RetryRestClient(executionsRestClient, options.retry); + this.executions = this._getRestClient('/actions/executions/:execution_id'); - const actionVersionRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/actions/:id/versions/:version_id`, - clientOptions, - options.tokenProvider - ); - this.actionVersions = new RetryRestClient(actionVersionRestClient, options.retry); + this.actionVersions = this._getRestClient('/actions/actions/:id/versions/:version_id'); - const deployActionVersionRestClient = new Auth0RestClient( - `${options.baseUrl}/actions/actions/:id/versions/:version_id/deploy`, - clientOptions, - options.tokenProvider + this.actionVersionDeploy = this._getRestClient( + '/actions/actions/:id/versions/:version_id/deploy' ); - this.actionVersionDeploy = new RetryRestClient(deployActionVersionRestClient, options.retry); } /** diff --git a/src/management/AttackProtectionManager.js b/src/management/AttackProtectionManager.js index f45ce542f..6edba6787 100644 --- a/src/management/AttackProtectionManager.js +++ b/src/management/AttackProtectionManager.js @@ -1,6 +1,4 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Simple facade for consuming a REST API endpoint. @@ -9,7 +7,7 @@ const RetryRestClient = require('../RetryRestClient'); * @see https://github.com/ngonzalvez/rest-facade */ -class AttackProtectionManager { +class AttackProtectionManager extends BaseManager { /** * @class * Abstracts interaction with the attack-protection endpoints. @@ -21,44 +19,17 @@ class AttackProtectionManager { * @param {object} [options.tokenProvider] Management API Token Provider */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } + super(options); - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } + this.bruteForceProtection = this._getRestClient('/attack-protection/brute-force-protection'); - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; - - const bruteForceProtection = new Auth0RestClient( - `${options.baseUrl}/attack-protection/brute-force-protection`, - clientOptions, - options.tokenProvider - ); - this.bruteForceProtection = new RetryRestClient(bruteForceProtection, options.retry); - - const suspiciousIpThrottling = new Auth0RestClient( - `${options.baseUrl}/attack-protection/suspicious-ip-throttling`, - clientOptions, - options.tokenProvider + this.suspiciousIpThrottling = this._getRestClient( + '/attack-protection/suspicious-ip-throttling' ); - this.suspiciousIpThrottling = new RetryRestClient(suspiciousIpThrottling, options.retry); - const breachedPasswordDetection = new Auth0RestClient( - `${options.baseUrl}/attack-protection/breached-password-detection`, - clientOptions, - options.tokenProvider + this.breachedPasswordDetection = this._getRestClient( + '/attack-protection/breached-password-detection' ); - this.breachedPasswordDetection = new RetryRestClient(breachedPasswordDetection, options.retry); } /** diff --git a/src/management/BaseManager.js b/src/management/BaseManager.js new file mode 100644 index 000000000..93ec257f9 --- /dev/null +++ b/src/management/BaseManager.js @@ -0,0 +1,39 @@ +const { ArgumentError } = require('rest-facade'); +const Auth0RestClient = require('../Auth0RestClient'); +const RetryRestClient = require('../RetryRestClient'); + +class BaseManager { + constructor(options) { + if (options === null || typeof options !== 'object') { + throw new ArgumentError('Must provide manager options'); + } + + if (options.baseUrl === null || options.baseUrl === undefined) { + throw new ArgumentError('Must provide a base URL for the API'); + } + + if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { + throw new ArgumentError('The provided base URL is invalid'); + } + + this._options = options; + } + + _getRestClient(path) { + const options = this._options; + const clientOptions = { + errorFormatter: { message: 'message', name: 'error' }, + headers: options.headers, + query: { repeatParams: false }, + }; + + const usersAuth0RestClient = new Auth0RestClient( + `${options.baseUrl}${path}`, + clientOptions, + options.tokenProvider + ); + return new RetryRestClient(usersAuth0RestClient, options.retry); + } +} + +module.exports = BaseManager; diff --git a/src/management/BlacklistedTokensManager.js b/src/management/BlacklistedTokensManager.js index a1a8d4eb9..3206eb88b 100644 --- a/src/management/BlacklistedTokensManager.js +++ b/src/management/BlacklistedTokensManager.js @@ -1,12 +1,10 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The BlacklistedTokensManager class provides methods to retrieve the list of * blacklisted tokens and blacklist new ones.. */ -class BlacklistedTokensManager { +class BlacklistedTokensManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,28 +12,7 @@ class BlacklistedTokensManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -43,12 +20,7 @@ class BlacklistedTokensManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/blacklists/tokens`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/blacklists/tokens'); } /** diff --git a/src/management/BrandingManager.js b/src/management/BrandingManager.js index b4cfb54da..abe51162c 100644 --- a/src/management/BrandingManager.js +++ b/src/management/BrandingManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Manages settings related to branding. */ -class BrandingManager { +class BrandingManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,23 +11,7 @@ class BrandingManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -37,12 +19,7 @@ class BrandingManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/branding`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/branding'); /** * Provides an abstraction layer for consuming the @@ -50,12 +27,7 @@ class BrandingManager { * * @type {external:RestClient} */ - const brandingTemplateAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/branding/templates/universal-login`, - clientOptions, - options.tokenProvider - ); - this.brandingTemplates = new RetryRestClient(brandingTemplateAuth0RestClient, options.retry); + this.brandingTemplates = this._getRestClient('/branding/templates/universal-login'); /** * Provides an abstraction layer for consuming the @@ -63,12 +35,7 @@ class BrandingManager { * * @type {external:RestClient} */ - const brandingThemesAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/branding/themes/:id`, - clientOptions, - options.tokenProvider - ); - this.brandingThemes = new RetryRestClient(brandingThemesAuth0RestClient, options.retry); + this.brandingThemes = this._getRestClient('/branding/themes/:id'); } /** diff --git a/src/management/ClientGrantsManager.js b/src/management/ClientGrantsManager.js index 6ddd50202..b93825f41 100644 --- a/src/management/ClientGrantsManager.js +++ b/src/management/ClientGrantsManager.js @@ -1,13 +1,11 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Auth0 Client Grants Manager. * * See {@link https://auth0.com/docs/api/v2#!/Client_Grants Client Grants} */ -class ClientGrantsManager { +class ClientGrantsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -15,28 +13,7 @@ class ClientGrantsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -44,12 +21,7 @@ class ClientGrantsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/client-grants/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/client-grants/:id'); } /** diff --git a/src/management/ClientsManager.js b/src/management/ClientsManager.js index 655e5161b..28943ed5d 100644 --- a/src/management/ClientsManager.js +++ b/src/management/ClientsManager.js @@ -1,6 +1,5 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Auth0 Clients Manager. @@ -11,7 +10,7 @@ const RetryRestClient = require('../RetryRestClient'); * {@link https://auth0.com/docs/applications Applications} section of the * documentation. */ -class ClientsManager { +class ClientsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -19,28 +18,7 @@ class ClientsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -48,12 +26,7 @@ class ClientsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/clients/:client_id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/clients/:client_id'); /** * Provides an abstraction layer for consuming the @@ -61,12 +34,7 @@ class ClientsManager { * * @type {external:RestClient} */ - const auth0RotateSecretClient = new Auth0RestClient( - `${options.baseUrl}/clients/:client_id/rotate-secret`, - clientOptions, - options.tokenProvider - ); - this.rotateSecretResource = new RetryRestClient(auth0RotateSecretClient, options.retry); + this.rotateSecretResource = this._getRestClient('/clients/:client_id/rotate-secret'); } /** diff --git a/src/management/ConnectionsManager.js b/src/management/ConnectionsManager.js index b4d3e4d6c..f63420e6a 100644 --- a/src/management/ConnectionsManager.js +++ b/src/management/ConnectionsManager.js @@ -1,11 +1,10 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Represents the relationship between Auth0 and an Identity provider. */ -class ConnectionsManager { +class ConnectionsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,27 +12,7 @@ class ConnectionsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,19 +21,9 @@ class ConnectionsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/connections/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/connections/:id'); - const statusClient = new Auth0RestClient( - `${options.baseUrl}/connections/:id/status`, - clientOptions, - options.tokenProvider - ); - this.status = new RetryRestClient(statusClient, options.retry); + this.status = this._getRestClient('/connections/:id/status'); /** * Provides an abstraction layer for consuming the @@ -63,12 +32,7 @@ class ConnectionsManager { * * @type {external:RestClient} */ - const userAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/connections/:id/users`, - clientOptions, - options.tokenProvider - ); - this.user = new RetryRestClient(userAuth0RestClient, options.retry); + this.user = this._getRestClient('/connections/:id/users'); } /** diff --git a/src/management/CustomDomainsManager.js b/src/management/CustomDomainsManager.js index 296ed61aa..d7825cf71 100644 --- a/src/management/CustomDomainsManager.js +++ b/src/management/CustomDomainsManager.js @@ -1,6 +1,5 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Auth0 Custom Domains Manager. @@ -11,7 +10,7 @@ const RetryRestClient = require('../RetryRestClient'); * {@link https://auth0.com/docs/custom-domains CustomDomains} section of the * documentation. */ -class CustomDomainsManager { +class CustomDomainsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -19,28 +18,7 @@ class CustomDomainsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -48,12 +26,7 @@ class CustomDomainsManager { * * @type {external:RestClient} */ - const auth0CustomDomainsRestClient = new Auth0RestClient( - `${options.baseUrl}/custom-domains/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0CustomDomainsRestClient, options.retry); + this.resource = this._getRestClient('/custom-domains/:id'); /** * Provides an abstraction layer for consuming the @@ -61,12 +34,7 @@ class CustomDomainsManager { * * @type {external:RestClient} */ - const auth0VerifyRestClient = new Auth0RestClient( - `${options.baseUrl}/custom-domains/:id/verify`, - clientOptions, - options.tokenProvider - ); - this.vefifyResource = new RetryRestClient(auth0VerifyRestClient, options.retry); + this.vefifyResource = this._getRestClient('/custom-domains/:id/verify'); } /** diff --git a/src/management/DeviceCredentialsManager.js b/src/management/DeviceCredentialsManager.js index 0143059a8..0d78b8dab 100644 --- a/src/management/DeviceCredentialsManager.js +++ b/src/management/DeviceCredentialsManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Manages Auth0 Device Credentials. */ -class DeviceCredentialsManager { +class DeviceCredentialsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,28 +11,13 @@ class DeviceCredentialsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } + super(options); /** * Options object for the RestClient instance. * * @type {object} */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; /** * Provides an abstraction layer for consuming the @@ -43,12 +26,7 @@ class DeviceCredentialsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/device-credentials/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/device-credentials/:id'); } /** diff --git a/src/management/EmailProviderManager.js b/src/management/EmailProviderManager.js index 2905b0d9f..ecc63d107 100644 --- a/src/management/EmailProviderManager.js +++ b/src/management/EmailProviderManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Auth0 Email Provider. */ -class EmailProviderManager { +class EmailProviderManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,28 +11,7 @@ class EmailProviderManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -42,12 +19,7 @@ class EmailProviderManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/emails/provider`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/emails/provider'); } /** diff --git a/src/management/EmailTemplatesManager.js b/src/management/EmailTemplatesManager.js index 3ff1cd1c7..45e94ce07 100644 --- a/src/management/EmailTemplatesManager.js +++ b/src/management/EmailTemplatesManager.js @@ -1,12 +1,10 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * This class provides a simple abstraction for performing CRUD operations * on Auth0's Email Templates. {@link https://auth0.com/docs/api/management/v2#!/Email_Templates/get_email_templates_by_templateName} */ -class EmailTemplatesManager { +class EmailTemplatesManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,23 +12,7 @@ class EmailTemplatesManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (!options || 'object' !== typeof options) { - throw new ArgumentError('Must provide manager options'); - } - - if (!options.baseUrl || 'string' !== typeof options.baseUrl) { - throw new ArgumentError('Must provide a valid string as base URL for the API'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -38,12 +20,7 @@ class EmailTemplatesManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/email-templates/:name`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/email-templates/:name'); } /** diff --git a/src/management/GrantsManager.js b/src/management/GrantsManager.js index bc5d3f2d2..dc2e6fbfe 100644 --- a/src/management/GrantsManager.js +++ b/src/management/GrantsManager.js @@ -1,13 +1,11 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Auth0 Grants Manager. * * See {@link https://auth0.com/docs/api/v2#!/Grants Grants} */ -class GrantsManager { +class GrantsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -15,28 +13,7 @@ class GrantsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -44,12 +21,7 @@ class GrantsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/grants/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/grants/:id'); } /** diff --git a/src/management/GuardianManager.js b/src/management/GuardianManager.js index 89d7de5a5..f6c7099b8 100644 --- a/src/management/GuardianManager.js +++ b/src/management/GuardianManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstracts interaction with the Guardian endpoint. */ -class GuardianManager { +class GuardianManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,127 +11,64 @@ class GuardianManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for retrieving Guardian enrollments. * * @type {external:RestClient} */ - const guardianEnrollmentsAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/enrollments/:id`, - clientOptions, - options.tokenProvider - ); - this.enrollments = new RetryRestClient(guardianEnrollmentsAuth0RestClient, options.retry); + this.enrollments = this._getRestClient('/guardian/enrollments/:id'); /** * Provides an abstraction layer for retrieving Guardian tickets. * * @type {external:RestClient} */ - const guardianTicketsAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/enrollments/ticket`, - clientOptions, - options.tokenProvider - ); - this.tickets = new RetryRestClient(guardianTicketsAuth0RestClient, options.retry); + this.tickets = this._getRestClient('/guardian/enrollments/ticket'); /** * Provides an abstraction layer for retrieving Guardian factors. * * @type {external:RestClient} */ - const guardianFactorsAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/factors/:name`, - clientOptions, - options.tokenProvider - ); - this.factors = new RetryRestClient(guardianFactorsAuth0RestClient, options.retry); + this.factors = this._getRestClient('/guardian/factors/:name'); /** * Provides an abstraction layer for configuring Factor settings * * @type {external:RestClient} */ - const guardianFactorSettingsAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/factors/:name/settings`, - clientOptions, - options.tokenProvider - ); - this.factorSettings = new RetryRestClient(guardianFactorSettingsAuth0RestClient, options.retry); + this.factorSettings = this._getRestClient('/guardian/factors/:name/settings'); /** * Provides an abstraction layer for retrieving Guardian factor templates. * * @type {external:RestClient} */ - const guardianFactorsTemplatesAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/factors/:name/templates`, - clientOptions, - options.tokenProvider - ); - this.factorsTemplates = new RetryRestClient( - guardianFactorsTemplatesAuth0RestClient, - options.retry - ); + this.factorsTemplates = this._getRestClient('/guardian/factors/:name/templates'); /** * Provides an abstraction layer for retrieving Guardian factor providers. * * @type {external:RestClient} */ - const guardianFactorsProvidersAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/factors/:name/providers/:provider`, - clientOptions, - options.tokenProvider - ); - this.factorsProviders = new RetryRestClient( - guardianFactorsProvidersAuth0RestClient, - options.retry - ); + this.factorsProviders = this._getRestClient('/guardian/factors/:name/providers/:provider'); /** * Provides an abstraction layer for retrieving Guardian policies. * * @type {external:RestClient} */ - const guardianPoliciesAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/policies`, - clientOptions, - options.tokenProvider - ); - this.policies = new RetryRestClient(guardianPoliciesAuth0RestClient, options.retry); + this.policies = this._getRestClient('/guardian/policies'); /** * Provides an abstraction layer for retrieving Guardian phone factor selected provider. * * @type {external:RestClient} */ - const guardianFactorsPhoneSelectedProviderAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/factors/sms/selected-provider`, - clientOptions, - options.tokenProvider - ); - this.factorsPhoneSelectedProvider = new RetryRestClient( - guardianFactorsPhoneSelectedProviderAuth0RestClient, - options.retry + this.factorsPhoneSelectedProvider = this._getRestClient( + '/guardian/factors/sms/selected-provider' ); /** @@ -141,15 +76,7 @@ class GuardianManager { * * @type {external:RestClient} */ - const guardianFactorsPhoneMessageTypesAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/guardian/factors/phone/message-types`, - clientOptions, - options.tokenProvider - ); - this.factorsPhoneMessageTypes = new RetryRestClient( - guardianFactorsPhoneMessageTypesAuth0RestClient, - options.retry - ); + this.factorsPhoneMessageTypes = this._getRestClient('/guardian/factors/phone/message-types'); } /** diff --git a/src/management/HooksManager.js b/src/management/HooksManager.js index ade851331..769e91491 100644 --- a/src/management/HooksManager.js +++ b/src/management/HooksManager.js @@ -1,12 +1,11 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The hooks manager class provides a simple abstraction for performing CRUD operations * on Auth0 HooksManagers. */ -class HooksManager { +class HooksManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,27 +13,7 @@ class HooksManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,19 +21,9 @@ class HooksManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/hooks/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/hooks/:id'); - const hookSecretsClient = new Auth0RestClient( - `${options.baseUrl}/hooks/:id/secrets`, - clientOptions, - options.tokenProvider - ); - this.secrets = new RetryRestClient(hookSecretsClient, options.retry); + this.secrets = this._getRestClient('/hooks/:id/secrets'); } /** diff --git a/src/management/JobsManager.js b/src/management/JobsManager.js index daa4ad680..ef156adc8 100644 --- a/src/management/JobsManager.js +++ b/src/management/JobsManager.js @@ -3,13 +3,12 @@ const FormData = require('form-data'); const fs = require('fs'); const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstract the creation as well as the retrieval of async jobs. */ -class JobsManager { +class JobsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -17,23 +16,7 @@ class JobsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); this.options = options; @@ -43,12 +26,7 @@ class JobsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/jobs/:id`, - clientOptions, - options.tokenProvider - ); - this.jobs = new RetryRestClient(auth0RestClient, options.retry); + this.jobs = this._getRestClient('/jobs/:id'); /** * Provides an abstraction layer for consuming the @@ -56,12 +34,7 @@ class JobsManager { * * @type {external:RestClient} */ - const jobErrorsRestClient = new Auth0RestClient( - `${options.baseUrl}/jobs/:id/errors`, - clientOptions, - options.tokenProvider - ); - this.jobErrors = new RetryRestClient(jobErrorsRestClient, options.retry); + this.jobErrors = this._getRestClient('/jobs/:id/errors'); /** * Provides an abstraction layer for consuming the @@ -69,12 +42,7 @@ class JobsManager { * * @type {external:RestClient} */ - const usersExportsRestClient = new Auth0RestClient( - `${options.baseUrl}/jobs/users-exports`, - clientOptions, - options.tokenProvider - ); - this.usersExports = new RetryRestClient(usersExportsRestClient, options.retry); + this.usersExports = this._getRestClient('/jobs/users-exports'); } /** diff --git a/src/management/LogStreamsManager.js b/src/management/LogStreamsManager.js index 086235463..59286554c 100644 --- a/src/management/LogStreamsManager.js +++ b/src/management/LogStreamsManager.js @@ -1,12 +1,10 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The logStreams class provides a simple abstraction for performing CRUD operations * on Auth0 Log Streams. */ -class LogStreamsManager { +class LogStreamsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,27 +12,7 @@ class LogStreamsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -43,12 +21,7 @@ class LogStreamsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/log-streams/:id `, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/log-streams/:id '); } /** diff --git a/src/management/LogsManager.js b/src/management/LogsManager.js index 4b61b4d24..b6b4e728f 100644 --- a/src/management/LogsManager.js +++ b/src/management/LogsManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Represents the relationship between Auth0 and an Identity provider. */ -class LogsManager { +class LogsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,27 +11,7 @@ class LogsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide client options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,12 +20,7 @@ class LogsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/logs/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/logs/:id'); } /** diff --git a/src/management/MigrationsManager.js b/src/management/MigrationsManager.js index fb9b94330..59305d071 100644 --- a/src/management/MigrationsManager.js +++ b/src/management/MigrationsManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstracts interaction with the migrations endpoint. */ -class MigrationsManager { +class MigrationsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,35 +11,14 @@ class MigrationsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the migrations endpoint * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/migrations`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/migrations'); } /** diff --git a/src/management/OrganizationsManager.js b/src/management/OrganizationsManager.js index 3a85e2a05..b60638b08 100644 --- a/src/management/OrganizationsManager.js +++ b/src/management/OrganizationsManager.js @@ -1,12 +1,11 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The organizations class provides a simple abstraction for performing CRUD operations * on Auth0 OrganizationsManager. */ -class OrganizationsManager { +class OrganizationsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,27 +13,7 @@ class OrganizationsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,47 +21,17 @@ class OrganizationsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/organizations/:id`, - clientOptions, - options.tokenProvider - ); - this.organizations = new RetryRestClient(auth0RestClient, options.retry); - - const connectionsInRoleClient = new Auth0RestClient( - `${options.baseUrl}/organizations/:id/enabled_connections/:connection_id`, - clientOptions, - options.tokenProvider - ); - this.connections = new RetryRestClient(connectionsInRoleClient, options.retry); - - const membersClient = new Auth0RestClient( - `${options.baseUrl}/organizations/:id/members/:user_id`, - clientOptions, - options.tokenProvider - ); - this.members = new RetryRestClient(membersClient, options.retry); - - const invitationClient = new Auth0RestClient( - `${options.baseUrl}/organizations/:id/invitations/:invitation_id`, - clientOptions, - options.tokenProvider - ); - this.invitations = new RetryRestClient(invitationClient, options.retry); - - const rolesClient = new Auth0RestClient( - `${options.baseUrl}/organizations/:id/members/:user_id/roles`, - clientOptions, - options.tokenProvider - ); - this.roles = new RetryRestClient(rolesClient, options.retry); - - const organizationByNameClient = new Auth0RestClient( - `${options.baseUrl}/organizations/name/:name`, - clientOptions, - options.tokenProvider - ); - this.organizationsByName = new RetryRestClient(organizationByNameClient, options.retry); + this.organizations = this._getRestClient('/organizations/:id'); + + this.connections = this._getRestClient('/organizations/:id/enabled_connections/:connection_id'); + + this.members = this._getRestClient('/organizations/:id/members/:user_id'); + + this.invitations = this._getRestClient('/organizations/:id/invitations/:invitation_id'); + + this.roles = this._getRestClient('/organizations/:id/members/:user_id/roles'); + + this.organizationsByName = this._getRestClient('/organizations/name/:name'); } /** diff --git a/src/management/PromptsManager.js b/src/management/PromptsManager.js index 31ebaf7b1..14a630f5b 100644 --- a/src/management/PromptsManager.js +++ b/src/management/PromptsManager.js @@ -1,11 +1,10 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Manages settings related to prompts. */ -class PromptsManager { +class PromptsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,23 +12,7 @@ class PromptsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -37,12 +20,7 @@ class PromptsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/prompts`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/prompts'); /** * Retrieve custom text for a specific prompt and language. @@ -51,15 +29,7 @@ class PromptsManager { * * @type {external:RestClient} */ - const customTextByLanguageAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/prompts/:prompt/custom-text/:language`, - clientOptions, - options.tokenProvider - ); - this.customTextByLanguage = new RetryRestClient( - customTextByLanguageAuth0RestClient, - options.retry - ); + this.customTextByLanguage = this._getRestClient('/prompts/:prompt/custom-text/:language'); } /** diff --git a/src/management/ResourceServersManager.js b/src/management/ResourceServersManager.js index 219eb385e..01823c20d 100644 --- a/src/management/ResourceServersManager.js +++ b/src/management/ResourceServersManager.js @@ -1,6 +1,4 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Auth0 Resource Servers Manager. @@ -11,7 +9,7 @@ const RetryRestClient = require('../RetryRestClient'); * {@link https://auth0.com/docs/api-auth API Authorization} section of the * documentation. */ -class ResourceServersManager { +class ResourceServersManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -19,27 +17,7 @@ class ResourceServersManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide resource server options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -47,12 +25,7 @@ class ResourceServersManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/resource-servers/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/resource-servers/:id'); } /** diff --git a/src/management/RolesManager.js b/src/management/RolesManager.js index 1e3042804..4f2739a43 100644 --- a/src/management/RolesManager.js +++ b/src/management/RolesManager.js @@ -1,12 +1,11 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The role class provides a simple abstraction for performing CRUD operations * on Auth0 RolesManager. */ -class RolesManager { +class RolesManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,27 +13,7 @@ class RolesManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,26 +21,11 @@ class RolesManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/roles/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/roles/:id'); - const permissionsInRoleClient = new Auth0RestClient( - `${options.baseUrl}/roles/:id/permissions`, - clientOptions, - options.tokenProvider - ); - this.permissions = new RetryRestClient(permissionsInRoleClient, options.retry); + this.permissions = this._getRestClient('/roles/:id/permissions'); - const usersInRoleClient = new Auth0RestClient( - `${options.baseUrl}/roles/:id/users`, - clientOptions, - options.tokenProvider - ); - this.users = new RetryRestClient(usersInRoleClient, options.retry); + this.users = this._getRestClient('/roles/:id/users'); } /** diff --git a/src/management/RulesConfigsManager.js b/src/management/RulesConfigsManager.js index eb0585a95..b6a9986ee 100644 --- a/src/management/RulesConfigsManager.js +++ b/src/management/RulesConfigsManager.js @@ -1,12 +1,10 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The rules configs manager class provides a simple abstraction for performing CRUD operations * on Auth0 RulesConfigsManager. */ -class RulesConfigsManager { +class RulesConfigsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,27 +12,7 @@ class RulesConfigsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,12 +20,7 @@ class RulesConfigsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/rules-configs/:key`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/rules-configs/:key'); } /** diff --git a/src/management/RulesManager.js b/src/management/RulesManager.js index cfe43574d..97ce98d15 100644 --- a/src/management/RulesManager.js +++ b/src/management/RulesManager.js @@ -1,12 +1,10 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * The rule class provides a simple abstraction for performing CRUD operations * on Auth0 RulesManagers. */ -class RulesManager { +class RulesManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,27 +12,7 @@ class RulesManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - /** - * Options object for the Rest Client instance. - * - * @type {object} - */ - const clientOptions = { - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for performing CRUD operations on @@ -42,12 +20,7 @@ class RulesManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/rules/:id`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/rules/:id'); } /** diff --git a/src/management/StatsManager.js b/src/management/StatsManager.js index 3dcd84359..ce3d049a0 100644 --- a/src/management/StatsManager.js +++ b/src/management/StatsManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstracts interaction with the stats endpoint. */ -class StatsManager { +class StatsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,23 +11,7 @@ class StatsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -37,12 +19,7 @@ class StatsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/stats/:type`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/stats/:type'); } /** diff --git a/src/management/TenantManager.js b/src/management/TenantManager.js index ecbd87a7d..26c11624f 100644 --- a/src/management/TenantManager.js +++ b/src/management/TenantManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstracts interaction with the tenant endpoint. */ -class TenantManager { +class TenantManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,23 +11,7 @@ class TenantManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -37,12 +19,7 @@ class TenantManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/tenants/settings`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/tenants/settings'); } /** diff --git a/src/management/TicketsManager.js b/src/management/TicketsManager.js index fc50ac419..9aca12102 100644 --- a/src/management/TicketsManager.js +++ b/src/management/TicketsManager.js @@ -1,11 +1,9 @@ -const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstracts interaction with the tickets endpoint. */ -class TicketsManager { +class TicketsManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,23 +11,7 @@ class TicketsManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); /** * Provides an abstraction layer for consuming the @@ -37,12 +19,7 @@ class TicketsManager { * * @type {external:RestClient} */ - const auth0RestClient = new Auth0RestClient( - `${options.baseUrl}/tickets/:type`, - clientOptions, - options.tokenProvider - ); - this.resource = new RetryRestClient(auth0RestClient, options.retry); + this.resource = this._getRestClient('/tickets/:type'); } /** diff --git a/src/management/UserBlocksManager.js b/src/management/UserBlocksManager.js index 3058fcdb6..c57a25fdf 100644 --- a/src/management/UserBlocksManager.js +++ b/src/management/UserBlocksManager.js @@ -1,11 +1,10 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); /** * Abstracts interaction with the user-blocks endpoint. */ -class UserBlocksManager { +class UserBlocksManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -13,40 +12,11 @@ class UserBlocksManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } - - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; + super(options); - const userBlocksByIdResource = new Auth0RestClient( - `${options.baseUrl}/user-blocks/:id`, - clientOptions, - options.tokenProvider - ); - this.userBlocksById = new RetryRestClient(userBlocksByIdResource, options.retry); + this.userBlocksById = this._getRestClient('/user-blocks/:id'); - const userBlocksByIdentifierResource = new Auth0RestClient( - `${options.baseUrl}/user-blocks`, - clientOptions, - options.tokenProvider - ); - this.userBlocksByIdentifier = new RetryRestClient( - userBlocksByIdentifierResource, - options.retry - ); + this.userBlocksByIdentifier = this._getRestClient('/user-blocks'); } /** diff --git a/src/management/UsersManager.js b/src/management/UsersManager.js index 20df90f0e..0d7e22383 100644 --- a/src/management/UsersManager.js +++ b/src/management/UsersManager.js @@ -1,12 +1,12 @@ const { ArgumentError } = require('rest-facade'); -const Auth0RestClient = require('../Auth0RestClient'); -const RetryRestClient = require('../RetryRestClient'); +const BaseManager = require('./BaseManager'); + const { sanitizeArguments } = require('../utils'); /** * Abstracts interaction with the users endpoint. */ -class UsersManager { +class UsersManager extends BaseManager { /** * @param {object} options The client options. * @param {string} options.baseUrl The URL of the API. @@ -14,30 +14,9 @@ class UsersManager { * @param {object} [options.retry] Retry Policy Config */ constructor(options) { - if (options === null || typeof options !== 'object') { - throw new ArgumentError('Must provide manager options'); - } - - if (options.baseUrl === null || options.baseUrl === undefined) { - throw new ArgumentError('Must provide a base URL for the API'); - } - - if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) { - throw new ArgumentError('The provided base URL is invalid'); - } + super(options); - const clientOptions = { - errorFormatter: { message: 'message', name: 'error' }, - headers: options.headers, - query: { repeatParams: false }, - }; - - const usersAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/users/:id`, - clientOptions, - options.tokenProvider - ); - this.users = new RetryRestClient(usersAuth0RestClient, options.retry); + this.users = this._getRestClient('/users/:id'); /** * Provides an abstraction layer for consuming the @@ -46,89 +25,50 @@ class UsersManager { * * @type {external:RestClient} */ - const multifactorAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/multifactor/:provider`, - clientOptions, - options.tokenProvider - ); - this.multifactor = new RetryRestClient(multifactorAuth0RestClient, options.retry); + this.multifactor = this._getRestClient('/users/:id/multifactor/:provider'); /** * Provides a simple abstraction layer for linking user accounts. * * @type {external:RestClient} */ - const identitiesAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/identities/:provider/:user_id`, - clientOptions, - options.tokenProvider - ); - this.identities = new RetryRestClient(identitiesAuth0RestClient, options.retry); + this.identities = this._getRestClient('/users/:id/identities/:provider/:user_id'); /** * Provides a simple abstraction layer for user logs * * @type {external:RestClient} */ - const userLogsAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/logs`, - clientOptions, - options.tokenProvider - ); - this.userLogs = new RetryRestClient(userLogsAuth0RestClient, options.retry); + this.userLogs = this._getRestClient('/users/:id/logs'); /** * Provides an abstraction layer for retrieving Guardian enrollments. * * @type {external:RestClient} */ - const enrollmentsAuth0RestClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/enrollments`, - clientOptions, - options.tokenProvider - ); - this.enrollments = new RetryRestClient(enrollmentsAuth0RestClient, options.retry); + this.enrollments = this._getRestClient('/users/:id/enrollments'); /** * Provides an abstraction layer for the new "users-by-email" API * * @type {external:RestClient} */ - const usersByEmailClient = new Auth0RestClient( - `${options.baseUrl}/users-by-email`, - clientOptions, - options.tokenProvider - ); - this.usersByEmail = new RetryRestClient(usersByEmailClient, options.retry); + this.usersByEmail = this._getRestClient('/users-by-email'); /** * Provides an abstraction layer for regenerating Guardian recovery codes. * * @type {external:RestClient} */ - const recoveryCodeRegenerationAuth0RestClients = new Auth0RestClient( - `${options.baseUrl}/users/:id/recovery-code-regeneration`, - clientOptions, - options.tokenProvider - ); - this.recoveryCodeRegenerations = new RetryRestClient( - recoveryCodeRegenerationAuth0RestClients, - options.retry - ); + this.recoveryCodeRegenerations = this._getRestClient('/users/:id/recovery-code-regeneration'); /** * Provides an abstraction layer for invalidating all remembered browsers for MFA. * * @type {external:RestClient} */ - const invalidateRememberBrowserAuth0RestClients = new Auth0RestClient( - `${options.baseUrl}/users/:id/multifactor/actions/invalidate-remember-browser`, - clientOptions, - options.tokenProvider - ); - this.invalidateRememberBrowsers = new RetryRestClient( - invalidateRememberBrowserAuth0RestClients, - options.retry + this.invalidateRememberBrowsers = this._getRestClient( + '/users/:id/multifactor/actions/invalidate-remember-browser' ); /** @@ -136,31 +76,16 @@ class UsersManager { * * @type {external:RestClient} */ - const userRolesClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/roles`, - clientOptions, - options.tokenProvider - ); - this.roles = new RetryRestClient(userRolesClient, options.retry); + this.roles = this._getRestClient('/users/:id/roles'); /** * Provides an abstraction layer for CRD on permissions directly on a user * * @type {external:RestClient} */ - const userPermissionsClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/permissions`, - clientOptions, - options.tokenProvider - ); - this.permissions = new RetryRestClient(userPermissionsClient, options.retry); + this.permissions = this._getRestClient('/users/:id/permissions'); - const organizationsClient = new Auth0RestClient( - `${options.baseUrl}/users/:id/organizations`, - clientOptions, - options.tokenProvider - ); - this.organizations = new RetryRestClient(organizationsClient, options.retry); + this.organizations = this._getRestClient('/users/:id/organizations'); } /** diff --git a/test/management/actions.tests.js b/test/management/actions.tests.js index 0a289f931..9e56109fd 100644 --- a/test/management/actions.tests.js +++ b/test/management/actions.tests.js @@ -44,7 +44,7 @@ describe('ActionsManager', () => { it('should error when no options are provided', () => { expect(() => { new ActionsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/blacklisted-tokens.tests.js b/test/management/blacklisted-tokens.tests.js index d5442fe15..c683798c1 100644 --- a/test/management/blacklisted-tokens.tests.js +++ b/test/management/blacklisted-tokens.tests.js @@ -29,7 +29,7 @@ describe('BlacklistedTokensManager', () => { it('should error when no options are provided', () => { expect(() => { new BlacklistedTokensManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/client-grants.tests.js b/test/management/client-grants.tests.js index f67f4f1a6..d55a13d05 100644 --- a/test/management/client-grants.tests.js +++ b/test/management/client-grants.tests.js @@ -35,7 +35,7 @@ describe('ClientGrantsManager', () => { it('should error when no options are provided', () => { expect(() => { new ClientGrantsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/client.tests.js b/test/management/client.tests.js index 5560554d6..001e80f84 100644 --- a/test/management/client.tests.js +++ b/test/management/client.tests.js @@ -41,7 +41,7 @@ describe('ClientsManager', () => { it('should error when no options are provided', () => { expect(() => { new ClientsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/connections.tests.js b/test/management/connections.tests.js index 39234304a..998247503 100644 --- a/test/management/connections.tests.js +++ b/test/management/connections.tests.js @@ -29,7 +29,7 @@ describe('ConnectionsManager', () => { it('should error when no options are provided', () => { expect(() => { new ConnectionsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/email-provider.tests.js b/test/management/email-provider.tests.js index 977f9bb11..1cd2c6de1 100644 --- a/test/management/email-provider.tests.js +++ b/test/management/email-provider.tests.js @@ -29,7 +29,7 @@ describe('EmailProviderManager', () => { it('should error when no options are provided', () => { expect(() => { new EmailProviderManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/email-templates.tests.js b/test/management/email-templates.tests.js index 8c3acd18d..388f5c4b6 100644 --- a/test/management/email-templates.tests.js +++ b/test/management/email-templates.tests.js @@ -45,13 +45,13 @@ describe('EmailTemplatesManager', () => { it('should throw an error when no base URL is provided', () => { expect(() => { new EmailTemplatesManager({}); - }).to.throw(ArgumentError, 'Must provide a valid string as base URL for the API'); + }).to.throw(ArgumentError, 'Must provide a base URL for the API'); }); it('should throw an error when the base URL is invalid', () => { expect(() => { new EmailTemplatesManager({ baseUrl: '' }); - }).to.throw(ArgumentError, 'Must provide a valid string as base URL for the API'); + }).to.throw(ArgumentError, 'The provided base URL is invalid'); }); }); diff --git a/test/management/grants.tests.js b/test/management/grants.tests.js index 11222d68d..d880effb1 100644 --- a/test/management/grants.tests.js +++ b/test/management/grants.tests.js @@ -35,7 +35,7 @@ describe('GrantsManager', () => { it('should error when no options are provided', () => { expect(() => { new GrantsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/jobs.tests.js b/test/management/jobs.tests.js index e1b7b8c74..63034999d 100644 --- a/test/management/jobs.tests.js +++ b/test/management/jobs.tests.js @@ -39,7 +39,7 @@ describe('JobsManager', () => { it('should error when no options are provided', () => { expect(() => { new JobsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/log-streams.tests.js b/test/management/log-streams.tests.js index 781ff921e..35e49661c 100644 --- a/test/management/log-streams.tests.js +++ b/test/management/log-streams.tests.js @@ -29,7 +29,7 @@ describe('LogStreamsManager', () => { it('should error when no options are provided', () => { expect(() => { new LogStreamsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/logs.tests.js b/test/management/logs.tests.js index d5ee44995..7aba08ecf 100644 --- a/test/management/logs.tests.js +++ b/test/management/logs.tests.js @@ -29,7 +29,7 @@ describe('LogsManager', () => { it('should error when no options are provided', () => { expect(() => { new LogsManager(); - }).to.throw(ArgumentError, 'Must provide client options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => { diff --git a/test/management/resource-servers.tests.js b/test/management/resource-servers.tests.js index fe391244b..dc56ecc02 100644 --- a/test/management/resource-servers.tests.js +++ b/test/management/resource-servers.tests.js @@ -35,7 +35,7 @@ describe('ResourceServersManager', () => { it('should error when no options are provided', () => { expect(() => { new ResourceServersManager(); - }).to.throw(ArgumentError, 'Must provide resource server options'); + }).to.throw(ArgumentError, 'Must provide manager options'); }); it('should throw an error when no base URL is provided', () => {