Skip to content

Commit

Permalink
Merge branch 'master' into deleteUserByEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpatrick authored Jun 30, 2020
2 parents e3b4b28 + a145941 commit 6b73a72
Show file tree
Hide file tree
Showing 6 changed files with 1,154 additions and 8 deletions.
174 changes: 174 additions & 0 deletions src/management/GuardianManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,48 @@ var GuardianManager = function(options) {
guardianFactorsProvidersAuth0RestClient,
options.retry
);

/**
* Provides an abstraction layer for retrieving Guardian policies.
*
* @type {external:RestClient}
*/
var guardianPoliciesAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/policies',
clientOptions,
options.tokenProvider
);
this.policies = new RetryRestClient(guardianPoliciesAuth0RestClient, options.retry);

/**
* Provides an abstraction layer for retrieving Guardian phone factor selected provider.
*
* @type {external:RestClient}
*/
var guardianFactorsPhoneSelectedProviderAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/sms/selected-provider',
clientOptions,
options.tokenProvider
);
this.factorsPhoneSelectedProvider = new RetryRestClient(
guardianFactorsPhoneSelectedProviderAuth0RestClient,
options.retry
);

/**
* Provides an abstraction layer for retrieving Guardian phone factor message types.
*
* @type {external:RestClient}
*/
var guardianFactorsPhoneMessageTypesAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/guardian/factors/phone/message-types',
clientOptions,
options.tokenProvider
);
this.factorsPhoneMessageTypes = new RetryRestClient(
guardianFactorsPhoneMessageTypesAuth0RestClient,
options.retry
);
};

/**
Expand Down Expand Up @@ -280,4 +322,136 @@ utils.wrapPropertyMethod(GuardianManager, 'updateFactorTemplates', 'factorsTempl
*/
utils.wrapPropertyMethod(GuardianManager, 'updateFactor', 'factors.update');

/**
* Get enabled Guardian policies
*
* @method getPolicies
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.getPolicies(function (err, policies) {
* console.log(policies);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'getPolicies', 'policies.get');

/**
* Update enabled Guardian policies
*
* @method updatePolicies
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.updatePolicies({}, [
* 'all-applications'
* ], function (err, policies) {
* console.log(policies);
* });
*
* @param {Object} params Parameters.
* @param {String[]} data Policies to enable. Empty array disables all policies.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(GuardianManager, 'updatePolicies', 'policies.update');

/**
* Get the Guardian phone factor's selected provider
*
* @method getPhoneFactorSelectedProvider
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.getPhoneFactorSelectedProvider(function (err, selectedProvider) {
* console.log(selectedProvider);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'getPhoneFactorSelectedProvider',
'factorsPhoneSelectedProvider.get'
);

/**
* Update the Guardian phone factor's selected provider
*
* @method updatePhoneFactorSelectedProvider
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.updatePhoneFactorSelectedProvider({}, {
* provider: 'twilio'
* }, function (err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Parameters.
* @param {Object} data Updated selected provider data.
* @param {String} data.provider Name of the selected provider
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'updatePhoneFactorSelectedProvider',
'factorsPhoneSelectedProvider.update'
);

/**
* Get the Guardian phone factor's message types
*
* @method getPhoneFactorMessageTypes
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.getPhoneFactorMessageTypes(function (err, messageTypes) {
* console.log(messageTypes);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'getPhoneFactorMessageTypes',
'factorsPhoneMessageTypes.get'
);

/**
* Update the Guardian phone factor's message types
*
* @method updatePhoneFactorMessageTypes
* @memberOf module:management.GuardianManager.prototype
*
* @example
* management.guardian.updatePhoneFactorMessageTypes({}, {
* message_types: ['sms', 'voice']
* }, function (err, factor) {
* console.log(factor);
* });
*
* @param {Object} params Parameters.
* @param {Object} data Updated selected provider data.
* @param {String[]} data.message_types Message types (only `"sms"` and `"voice"` are supported).
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(
GuardianManager,
'updatePhoneFactorMessageTypes',
'factorsPhoneMessageTypes.update'
);

module.exports = GuardianManager;
108 changes: 108 additions & 0 deletions src/management/MigrationsManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
var ArgumentError = require('rest-facade').ArgumentError;
var Auth0RestClient = require('../Auth0RestClient');
var RetryRestClient = require('../RetryRestClient');

/**
* @class
* Abstracts interaction with the migrations endpoint.
* @constructor
* @memberOf module:management
*
* @param {Object} options The client options.
* @param {String} options.baseUrl The URL of the API.
* @param {Object} [options.headers] Headers to be included in all requests.
* @param {Object} [options.retry] Retry Policy Config
*/
var MigrationsManager = function(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');
}

var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};

/**
* Provides an abstraction layer for consuming the migrations endpoint
*
* @type {external:RestClient}
*/
var auth0RestClient = new Auth0RestClient(
options.baseUrl + '/migrations',
clientOptions,
options.tokenProvider
);
this.resource = new RetryRestClient(auth0RestClient, options.retry);
};

/**
* Update the tenant migrations.
*
* @method updateMigrations
* @memberOf module:management.MigrationsManager.prototype
*
* @example
* management.migrations.updateMigrations(data, function (err) {
* if (err) {
* // Handle error.
* }
* });
*
* @param {Object} data The tenant migrations to be updated
* @param {Object} data.flags The tenant migrations flags to be updated
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
MigrationsManager.prototype.updateMigrations = function(data, cb) {
if (cb && cb instanceof Function) {
return this.resource.patch({}, data, cb);
}

// Return a promise.
return this.resource.patch({}, data);
};

/**
* Get the tenant migrations.
*
* @method getMigrations
* @memberOf module:management.MigrationsManager.prototype
*
* @example
* management.migrations.getMigrations(function (err, migrations) {
* if (err) {
* // Handle error.
* }
*
* console.log(migrations.flags);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
MigrationsManager.prototype.getMigrations = function(data, cb) {
if (data instanceof Function && !cb) {
cb = data;
data = {};
}
if (cb && cb instanceof Function) {
return this.resource.get(data, cb);
}

// Return a promise.
return this.resource.get(data);
};

module.exports = MigrationsManager;
Loading

0 comments on commit 6b73a72

Please sign in to comment.