-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #370 from chrisscott/branding_prompts
Add Management API support for Branding and Prompts endpoints.
- Loading branch information
Showing
4 changed files
with
666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var ArgumentError = require('rest-facade').ArgumentError; | ||
var utils = require('../utils'); | ||
var Auth0RestClient = require('../Auth0RestClient'); | ||
var RetryRestClient = require('../RetryRestClient'); | ||
|
||
/** | ||
* Simple facade for consuming a REST API endpoint. | ||
* @external RestClient | ||
* @see https://github.com/ngonzalvez/rest-facade | ||
*/ | ||
|
||
/** | ||
* @class BrandingManager | ||
* Manages settings related to branding. | ||
* @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 BrandingManager = 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/management/v2#!/Branding Branding endpoint}. | ||
* | ||
* @type {external:RestClient} | ||
*/ | ||
var auth0RestClient = new Auth0RestClient( | ||
options.baseUrl + '/branding', | ||
clientOptions, | ||
options.tokenProvider | ||
); | ||
this.resource = new RetryRestClient(auth0RestClient, options.retry); | ||
}; | ||
|
||
/** | ||
* Update the branding settings. | ||
* | ||
* @method updateSettings | ||
* @memberOf module:management.BrandingManager.prototype | ||
* | ||
* @example | ||
* management.branding.updateSettings(data, function (err, branding) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* // Updated branding | ||
* console.log(branding); | ||
* }); | ||
* | ||
* @param {Object} params Branding parameters. | ||
* @param {Object} data Updated branding data. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(BrandingManager, 'updateSettings', 'resource.patch'); | ||
|
||
/** | ||
* Get the branding settings.. | ||
* | ||
* @method getSettings | ||
* @memberOf module:management.BrandingManager.prototype | ||
* | ||
* @example | ||
* management.branding.getSettings(data, function (err, branding) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* // Branding | ||
* console.log(branding); | ||
* }); | ||
* | ||
* @param {Object} params Branding parameters. | ||
* @param {Object} data Branding data. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(BrandingManager, 'getSettings', 'resource.get'); | ||
|
||
module.exports = BrandingManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
var ArgumentError = require('rest-facade').ArgumentError; | ||
var utils = require('../utils'); | ||
var Auth0RestClient = require('../Auth0RestClient'); | ||
var RetryRestClient = require('../RetryRestClient'); | ||
|
||
/** | ||
* Simple facade for consuming a REST API endpoint. | ||
* @external RestClient | ||
* @see https://github.com/ngonzalvez/rest-facade | ||
*/ | ||
|
||
/** | ||
* @class PromptsManager | ||
* Manages settings related to prompts. | ||
* @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 PromptsManager = 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/management/v2#!/Prompts Prompts endpoint}. | ||
* | ||
* @type {external:RestClient} | ||
*/ | ||
var auth0RestClient = new Auth0RestClient( | ||
options.baseUrl + '/prompts', | ||
clientOptions, | ||
options.tokenProvider | ||
); | ||
this.resource = new RetryRestClient(auth0RestClient, options.retry); | ||
}; | ||
|
||
/** | ||
* Update the prompts settings. | ||
* | ||
* @method updateSettings | ||
* @memberOf module:management.PromptsManager.prototype | ||
* | ||
* @example | ||
* management.prompts.updateSettings(data, function (err, prompts) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* // Updated prompts | ||
* console.log(prompts); | ||
* }); | ||
* | ||
* @param {Object} params Prompts parameters. | ||
* @param {Object} data Updated prompts data. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(PromptsManager, 'updateSettings', 'resource.patch'); | ||
|
||
/** | ||
* Get the prompts settings.. | ||
* | ||
* @method getSettings | ||
* @memberOf module:management.PromptsManager.prototype | ||
* | ||
* @example | ||
* management.prompts.getSettings(data, function (err, prompts) { | ||
* if (err) { | ||
* // Handle error. | ||
* } | ||
* | ||
* // Prompts | ||
* console.log(prompts); | ||
* }); | ||
* | ||
* @param {Object} params Prompts parameters. | ||
* @param {Object} data Prompts data. | ||
* @param {Function} [cb] Callback function. | ||
* | ||
* @return {Promise|undefined} | ||
*/ | ||
utils.wrapPropertyMethod(PromptsManager, 'getSettings', 'resource.get'); | ||
|
||
module.exports = PromptsManager; |
Oops, something went wrong.