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

Use id instead of action_id as per the mgmt api. #622

Merged
merged 3 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 96 additions & 27 deletions src/management/ActionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ var ActionsManager = function(options) {
* @type {external:RestClient}
*/
var auth0RestClient = new Auth0RestClient(
options.baseUrl + '/actions/actions/:action_id',
options.baseUrl + '/actions/actions/:id',
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
clientOptions,
options.tokenProvider
);
this.resource = new RetryRestClient(auth0RestClient, options.retry);

var actionsDeployRestClient = new Auth0RestClient(
options.baseUrl + '/actions/actions/:action_id/deploy',
options.baseUrl + '/actions/actions/:id/deploy',
clientOptions,
options.tokenProvider
);
this.actionsDeploy = new RetryRestClient(actionsDeployRestClient, options.retry);

var actionsTestRestClient = new Auth0RestClient(
options.baseUrl + '/actions/actions/:action_id/test',
options.baseUrl + '/actions/actions/:id/test',
clientOptions,
options.tokenProvider
);
Expand Down Expand Up @@ -102,14 +102,14 @@ var ActionsManager = function(options) {
this.executions = new RetryRestClient(executionsRestClient, options.retry);

var actionVersionRestClient = new Auth0RestClient(
options.baseUrl + '/actions/actions/:action_id/versions/:version_id',
options.baseUrl + '/actions/actions/:id/versions/:version_id',
clientOptions,
options.tokenProvider
);
this.actionVersions = new RetryRestClient(actionVersionRestClient, options.retry);

var deployActionVersionRestClient = new Auth0RestClient(
options.baseUrl + '/actions/actions/:action_id/versions/:version_id/deploy',
options.baseUrl + '/actions/actions/:id/versions/:version_id/deploy',
clientOptions,
options.tokenProvider
);
Expand Down Expand Up @@ -320,7 +320,7 @@ utils.wrapPropertyMethod(ActionsManager, 'getAll', 'resource.getAll');
* @memberOf module:management.ActionsManager.prototype
*
* @example
* management.actions.get({ action_id: ACTION_ID }, function (err, action) {
* management.actions.get({ id: ACTION_ID }, function (err, action) {
* if (err) {
* // Handle error.
* }
Expand All @@ -329,12 +329,25 @@ utils.wrapPropertyMethod(ActionsManager, 'getAll', 'resource.getAll');
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ActionsManager, 'get', 'resource.get');
ActionsManager.prototype.get = function(params, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏


if (cb && cb instanceof Function) {
return this.resource.get(params, cb);
}

return this.resource.get(params);
};

/**
* Update an existing action.
Expand All @@ -344,7 +357,7 @@ utils.wrapPropertyMethod(ActionsManager, 'get', 'resource.get');
*
* @example
* var data = { name: 'new-name' };
* var params = { action_id: ACTION_ID };
* var params = { id: ACTION_ID };
*
* // Using auth0 instance.
* management.updateAction(params, data, function (err, action) {
Expand All @@ -365,13 +378,26 @@ utils.wrapPropertyMethod(ActionsManager, 'get', 'resource.get');
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {Object} data Updated action data.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ActionsManager, 'update', 'resource.patch');
ActionsManager.prototype.update = function(params, data, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.resource.patch(params, data, cb);
}

return this.resource.patch(params, data);
};

/**
* Delete an existing action. Deleting an Action deletes all the action's versions
Expand All @@ -380,7 +406,7 @@ utils.wrapPropertyMethod(ActionsManager, 'update', 'resource.patch');
* @memberOf module:management.ActionsManager.prototype
*
* @example
* management.actions.delete({ action_id: ACTION_ID }, function (err) {
* management.actions.delete({ id: ACTION_ID }, function (err) {
* if (err) {
* // Handle error.
* }
Expand All @@ -389,12 +415,25 @@ utils.wrapPropertyMethod(ActionsManager, 'update', 'resource.patch');
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
utils.wrapPropertyMethod(ActionsManager, 'delete', 'resource.delete');
ActionsManager.prototype.delete = function(params, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.resource.delete(params, cb);
}

return this.resource.delete(params);
};

/**
* test an Action.
Expand All @@ -403,7 +442,7 @@ utils.wrapPropertyMethod(ActionsManager, 'delete', 'resource.delete');
* @memberOf module:management.ActionsManager.prototype
*
* @example
* var params = { action_id: ACTION_ID};
* var params = { id: ACTION_ID};
* management.actions.testAction(params, payload, function (err) {
* if (err) {
* // Handle error.
Expand All @@ -412,7 +451,7 @@ utils.wrapPropertyMethod(ActionsManager, 'delete', 'resource.delete');
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {Object} payload Payload represents the entire structure necessary to test a particular trigger
* @param {Function} [cb] Callback function.
*
Expand All @@ -422,6 +461,11 @@ ActionsManager.prototype.test = function(params, payload, cb) {
params = params || {};
payload = payload || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.actionsTest.create(params, payload, cb);
}
Expand All @@ -437,7 +481,7 @@ ActionsManager.prototype.test = function(params, payload, cb) {
* @memberOf module:management.ActionsManager.prototype
*
* @example
* var params = { action_id: ACTION_ID};
* var params = { id: ACTION_ID};
* mangement.actions.deploy(params, function (err, actionVersion) {
* if (err) {
* // Handle error.
Expand All @@ -446,14 +490,19 @@ ActionsManager.prototype.test = function(params, payload, cb) {
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
ActionsManager.prototype.deploy = function(params, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.actionsDeploy.create(params, {}, cb);
}
Expand All @@ -478,21 +527,26 @@ ActionsManager.prototype.deploy = function(params, cb) {
* page: 0
* };
*
* management.actions.getVersions({ action_id: ACTION_ID }, function (err, actionVersions) {
* management.actions.getVersions({ id: ACTION_ID }, function (err, actionVersions) {
* console.log(actionVersions.length);
* });
*
* @param {Object} [params] ActionVersions parameters.
* @param {Number} [params.per_page] Number of results per page.
* @param {Number} [params.page] Page number, zero indexed.
* @param {String} [params.action_id] Action ID.
* @param {String} [params.id] Action ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/
ActionsManager.prototype.getVersions = function(params, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.actionVersions.getAll(params, cb);
}
Expand All @@ -507,7 +561,7 @@ ActionsManager.prototype.getVersions = function(params, cb) {
* @memberOf module:management.ActionsManager.prototype
*
* @example
* var params = { action_id: ACTION_ID, version_id: VERSION_ID };
* var params = { id: ACTION_ID, version_id: VERSION_ID };
* management.actions.getVersion(params, function (err, actionVersion) {
* if (err) {
* // Handle error.
Expand All @@ -516,7 +570,7 @@ ActionsManager.prototype.getVersions = function(params, cb) {
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {String} params.version_id ActionVersion ID.
* @param {Function} [cb] Callback function.
*
Expand All @@ -525,6 +579,11 @@ ActionsManager.prototype.getVersions = function(params, cb) {
ActionsManager.prototype.getVersion = function(params, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.actionVersions.get(params, cb);
}
Expand All @@ -542,15 +601,15 @@ ActionsManager.prototype.getVersion = function(params, cb) {
* @memberOf module:management.ActionsManager.prototype
*
* @example
* var params = { action_id: ACTION_ID };
* var params = { id: ACTION_ID };
* management.actions.createActionVersion(params, data, function (err, actionVersion) {
* if (err) {
* // Handle error.
* }
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {Object} data ActionVersion parameters.
* @param {Function} [cb] Callback function.
*
Expand All @@ -559,6 +618,11 @@ ActionsManager.prototype.getVersion = function(params, cb) {
ActionsManager.prototype.createVersion = function(params, data, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.actionVersions.create(params, data, cb);
}
Expand All @@ -573,7 +637,7 @@ ActionsManager.prototype.createVersion = function(params, data, cb) {
* @memberOf module:management.ActionsManager.prototype
*
* @example
* var params = { action_id: ACTION_ID, version_id: VERSION_ID };
* var params = { id: ACTION_ID, version_id: VERSION_ID };
* management.actions.deployVersion(params, function (err, actionVersion) {
* if (err) {
* // Handle error.
Expand All @@ -582,7 +646,7 @@ ActionsManager.prototype.createVersion = function(params, data, cb) {
* });
*
* @param {Object} params Action parameters.
* @param {String} params.action_id Action ID.
* @param {String} params.id Action ID.
* @param {String} params.version_id Action ID.
* @param {Function} [cb] Callback function.
*
Expand All @@ -591,6 +655,11 @@ ActionsManager.prototype.createVersion = function(params, data, cb) {
ActionsManager.prototype.deployVersion = function(params, cb) {
params = params || {};

if (params.action_id) {
params.id = params.action_id;
delete params.action_id;
}

if (cb && cb instanceof Function) {
return this.actionVersionDeploy.create(params, {}, cb);
}
Expand All @@ -614,7 +683,7 @@ ActionsManager.prototype.deployVersion = function(params, cb) {
* });
*
* @param {Object} params Action Execution parameters.
* @param {String} params.execution_id Action Execution ID.
* @param {String} params.id Action Execution ID.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
Expand Down
Loading