Skip to content

Commit

Permalink
Adding Prompts Manager (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpatrick authored Sep 17, 2020
1 parent 2dbf44a commit 160b647
Show file tree
Hide file tree
Showing 4 changed files with 393 additions and 1 deletion.
106 changes: 106 additions & 0 deletions src/management/PromptsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ var PromptsManager = function(options) {
options.tokenProvider
);
this.resource = new RetryRestClient(auth0RestClient, options.retry);

/**
* Retrieve custom text for a specific prompt and language.
* {@link https://auth0.com/docs/api/management/v2#!/Prompts/get_custom_text_by_language Custom Text endpoint}
*
*
* @type {external:RestClient}
*/
var customTextByLanguageAuth0RestClient = new Auth0RestClient(
options.baseUrl + '/prompts/:prompt/custom-text/:language',
clientOptions,
options.tokenProvider
);
this.customTextByLanguage = new RetryRestClient(
customTextByLanguageAuth0RestClient,
options.retry
);
};

/**
Expand Down Expand Up @@ -101,4 +118,93 @@ utils.wrapPropertyMethod(PromptsManager, 'updateSettings', 'resource.patch');
*/
utils.wrapPropertyMethod(PromptsManager, 'getSettings', 'resource.get');

/**
* Retrieve custom text for a specific prompt and language.
*
* @method getCustomTextByLanguage
* @memberOf module:management.PromptsManager.prototype
*
* @example
* var params = { prompt: PROMPT_NAME, language: LANGUAGE };
*
* management.prompts.getCustomTextByLanguage(params, function (err, customText) {
* if (err) {
* // Handle error.
* }
*
* console.log('CustomText', customText);
* });
*
* @param {Object} params Data object.
* @param {String} params.prompt Name of the prompt.
* @param {String} params.language Language to retrieve.
* @param {Function} [cb] Callback function
*
* @return {Promise|undefined}
*/
PromptsManager.prototype.getCustomTextByLanguage = function(params, cb) {
params = params || {};

if (!params.prompt || typeof params.prompt !== 'string') {
throw new ArgumentError('The prompt parameter must be a string');
}

if (!params.language || typeof params.language !== 'string') {
throw new ArgumentError('The language parameter must be a string');
}

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

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

/**
* Set custom text for a specific prompt.
*
* @method updateCustomTextByLanguage
* @memberOf module:management.PromptsManager.prototype
*
* @example
* var params = { prompt: PROMPT_NAME, language: LANGUAGE, body: BODY_OBJECT };
*
* management.prompts.updateCustomTextByLanguage(params, function (err, customText) {
* if (err) {
* // Handle error.
* }
*
* console.log('CustomText', customText);
* });
*
* @param {Object} params Data object.
* @param {String} params.prompt Name of the prompt.
* @param {String} params.language Language to retrieve.
* @param {Object} params.body An object containing custom dictionaries for a group of screens.
* @param {Function} [cb] Callback function
*
* @return {Promise|undefined}
*/
PromptsManager.prototype.updateCustomTextByLanguage = function(params, cb) {
params = params || {};

if (!params.prompt || typeof params.prompt !== 'string') {
throw new ArgumentError('The prompt parameter must be a string');
}

if (!params.language || typeof params.language !== 'string') {
throw new ArgumentError('The language parameter must be a string');
}

if (!params.body || typeof params.body !== 'object') {
throw new ArgumentError('The body parameter must be an object');
}

if (cb && cb instanceof Function) {
return this.customTextByLanguage.update(params, params.body, cb);
}

return this.customTextByLanguage.update(params, params.body);
};

module.exports = PromptsManager;
114 changes: 114 additions & 0 deletions src/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var RolesManager = require('./RolesManager');
var HooksManager = require('./HooksManager');
var BrandingManager = require('./BrandingManager');
var MigrationsManager = require('./MigrationsManager');
var PromptsManager = require('./PromptsManager');

var BASE_URL_FORMAT = 'https://%s/api/v2';
var MANAGEMENT_API_AUD_FORMAT = 'https://%s/api/v2/';
Expand Down Expand Up @@ -343,6 +344,13 @@ var ManagementClient = function(options) {
* @type {MigrationsManager}
*/
this.migrations = new MigrationsManager(managerOptions);

/**
* Prompts Manager
*
* @type {PromptsManager}
*/
this.prompts = new PromptsManager(managerOptions);
};

/**
Expand Down Expand Up @@ -3548,4 +3556,110 @@ utils.wrapPropertyMethod(ManagementClient, 'updateMigrations', 'migrations.updat
*/
utils.wrapPropertyMethod(ManagementClient, 'getMigrations', 'migrations.getMigrations');

/**
* Get prompts settings..
*
* @method getPromptsSettings
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.getPromptsSettings(function (err, settings) {
* if (err) {
* // Handle error.
* }
*
* console.log(settings);
* });
*
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/

utils.wrapPropertyMethod(ManagementClient, 'getPromptsSettings', 'prompts.getSettings');

/**
* Update prompts settings.
*
* @method updatePromptsSettings
* @memberOf module:management.ManagementClient.prototype
*
* @example
* management.updatePromptsSettings(data, function (err) {
* if (err) {
* // Handle error.
* }
* });
*
* @param {Object} data The new prompts settings.
* @param {Function} [cb] Callback function.
*
* @return {Promise|undefined}
*/

utils.wrapPropertyMethod(ManagementClient, 'updatePromptsSettings', 'prompts.updateSettings');

/**
* Retrieve custom text for a specific prompt and language.
*
* @method getCustomTextByLanguage
* @memberOf module:management.PromptsManager.prototype
*
* @example
* var params = { prompt: PROMPT_NAME, language: LANGUAGE };
*
* management.prompts.getCustomTextByLanguage(params, function (err, customText) {
* if (err) {
* // Handle error.
* }
*
* console.log('CustomText', customText);
* });
*
* @param {Object} params Data object.
* @param {String} params.prompt Name of the prompt.
* @param {String} params.language Language to retrieve.
* @param {Function} [cb] Callback function
*
* @return {Promise|undefined}
*/

utils.wrapPropertyMethod(
ManagementClient,
'getCustomTextByLanguage',
'prompts.getCustomTextByLanguage'
);

/**
* Set custom text for a specific prompt.
*
* @method updateCustomTextByLanguage
* @memberOf module:management.PromptsManager.prototype
*
* @example
* var params = { prompt: PROMPT_NAME, language: LANGUAGE, body: BODY_OBJECT };
*
* management.prompts.updateCustomTextByLanguage(params, function (err, customText) {
* if (err) {
* // Handle error.
* }
*
* console.log('CustomText', customText);
* });
*
* @param {Object} params Data object.
* @param {String} params.prompt Name of the prompt.
* @param {String} params.language Language to retrieve.
* @param {Object} params.body An object containing custom dictionaries for a group of screens.
* @param {Function} [cb] Callback function
*
* @return {Promise|undefined}
*/

utils.wrapPropertyMethod(
ManagementClient,
'updateCustomTextByLanguage',
'prompts.updateCustomTextByLanguage'
);

module.exports = ManagementClient;
4 changes: 3 additions & 1 deletion test/management/management-client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,9 @@ describe('ManagementClient', function() {
'unblockUser',
'getUserBlocksByIdentifier',
'unblockUserByIdentifier',
'getAccessToken'
'getAccessToken',
'getPromptsSettings',
'updatePromptsSettings'
];

before(function() {
Expand Down
Loading

0 comments on commit 160b647

Please sign in to comment.