Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(migrations): adds migrations manager #503

Merged
merged 7 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 109 additions & 0 deletions src/management/MigrationsManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
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
* {@link https://auth0.com/docs/api/v2#!/Stats Stats endpoint}.
CriGoT marked this conversation as resolved.
Show resolved Hide resolved
*
* @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.tmigrations.updateMigrations(data, function (err) {
CriGoT marked this conversation as resolved.
Show resolved Hide resolved
* 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
CriGoT marked this conversation as resolved.
Show resolved Hide resolved
*
* @example
* management.migrations.getMigrations(function (err, settings) {
* if (err) {
* // Handle error.
* }
*
* console.log(settings);
* });
CriGoT marked this conversation as resolved.
Show resolved Hide resolved
*
* @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;
54 changes: 54 additions & 0 deletions src/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var CustomDomainsManager = require('./CustomDomainsManager');
var RolesManager = require('./RolesManager');
var HooksManager = require('./HooksManager');
var BrandingManager = require('./BrandingManager');
var MigrationsManager = require('./MigrationsManager');

var BASE_URL_FORMAT = 'https://%s/api/v2';
var MANAGEMENT_API_AUD_FORMAT = 'https://%s/api/v2/';
Expand Down Expand Up @@ -327,6 +328,13 @@ var ManagementClient = function(options) {
* @type {HooksManager}
*/
this.branding = new BrandingManager(managerOptions);

/**
* ManagementClient migrationss manager.
CriGoT marked this conversation as resolved.
Show resolved Hide resolved
*
* @type {MigrationsManager}
*/
this.migrations = new MigrationsManager(managerOptions);
};

/**
Expand Down Expand Up @@ -3212,4 +3220,50 @@ utils.wrapPropertyMethod(ManagementClient, 'updateBrandingSettings', 'branding.u
*/
utils.wrapPropertyMethod(ManagementClient, 'getBrandingSettings', 'branding.getSettings');

/**
* Update the tenant migrations.
*
* @method updateMigrations
* @memberOf module:management.ManagementClient.prototype
*
* @example
* data = { flags: { migration: true } };
* management.updateMigrations(data, function (err, migrations) {
* if (err) {
* // Handle error.
* }
*
* // Updated migrations flags
* console.log(migrations.flags);
* });
*
* @param {Object} data Updated migrations data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'updateMigrations', 'migrations.updateMigrations');

/**
* Get migrations flags
*
* @method getMigrations
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.getMigrations(function (err, migrations) {
* if (err) {
* // Handle error.
* }
*
* // Migration flags
* console.log(migrations.flags);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ManagementClient, 'getMigrations', 'migrations.getMigrations');

module.exports = ManagementClient;