Skip to content

Commit

Permalink
Update packages and utilize error classes from rest-facade correctly (F…
Browse files Browse the repository at this point in the history
…ixes #154) (#183)

* - Use error classes from rest-facade for consistency
- Fix APIError not being constructed correctly by rest-facade due to missing errorFormatter config
- Fix test case in oauth.tests.js incorrectly using return twice
* - Revert bluebird version to be inline with rest-facade
  • Loading branch information
charsleysa authored and hzalaz committed Jun 16, 2017
1 parent cdcf916 commit f2ed9a6
Show file tree
Hide file tree
Showing 47 changed files with 85 additions and 81 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"dependencies": {
"bluebird": "^2.10.2",
"request": "^2.81.0",
"rest-facade": "^1.2.7",
"url-join": "0.0.1"
"rest-facade": "^1.5.0",
"url-join": "2.0.2"
},
"devDependencies": {
"chai": "^2.2.0",
Expand Down
13 changes: 10 additions & 3 deletions src/auth/DatabaseAuthenticator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var extend = require('util')._extend;

var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var RestClient = require('rest-facade').Client;


Expand All @@ -25,10 +25,17 @@ var DatabaseAuthenticator = function (options, oauth) {
throw new ArgumentError('The authenticator options must be an object');
}

var dbConnectionsUrl = options.baseUrl + '/dbconnections/:type';
/**
* Options object for the Rest Client instace.
*
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' }
};

this.oauth = oauth;
this.dbConnections = new RestClient(dbConnectionsUrl);
this.dbConnections = new RestClient(options.baseUrl + '/dbconnections/:type', clientOptions);
this.clientId = options.clientId;
};

Expand Down
13 changes: 10 additions & 3 deletions src/auth/OAuthAuthenticator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var extend = require('util')._extend;

var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var RestClient = require('rest-facade').Client;


Expand All @@ -25,9 +25,16 @@ var OAuthAuthenticator = function (options) {
throw new ArgumentError('The authenticator options must be an object');
}

var oauthUrl = options.baseUrl + '/oauth/:type';
/**
* Options object for the Rest Client instace.
*
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' }
};

this.oauth = new RestClient(oauthUrl);
this.oauth = new RestClient(options.baseUrl + '/oauth/:type', clientOptions);
this.clientId = options.clientId;
this.clientSecret = options.clientSecret;
};
Expand Down
13 changes: 10 additions & 3 deletions src/auth/PasswordlessAuthenticator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var extend = require('util')._extend;

var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var RestClient = require('rest-facade').Client;


Expand All @@ -24,10 +24,17 @@ var PasswordlessAuthenticator = function (options, oauth) {
throw new ArgumentError('The authenticator options must be an object');
}

var baseUrl = options.baseUrl + '/passwordless/start';
/**
* Options object for the Rest Client instace.
*
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' }
};

this.oauth = oauth;
this.passwordless = new RestClient(baseUrl);
this.passwordless = new RestClient(options.baseUrl + '/passwordless/start', clientOptions);
this.clientId = options.clientId;
};

Expand Down
2 changes: 1 addition & 1 deletion src/auth/TokensManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var extend = require('util')._extend;
var getRequestPromise = require('../utils').getRequestPromise;

var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand Down
2 changes: 1 addition & 1 deletion src/auth/UsersManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var extend = require('util')._extend;
var getRequestPromise = require('../utils').getRequestPromise;

var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand Down
2 changes: 1 addition & 1 deletion src/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var util = require('util');
var pkg = require('../../package.json');
var utils = require('../utils');
var jsonToBase64 = utils.jsonToBase64;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;

// Authenticators.
var OAuthAuthenticator = require('./OAuthAuthenticator');
Expand Down
11 changes: 0 additions & 11 deletions src/exceptions/ApiError.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/exceptions/ArgumentError.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/exceptions/index.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/management/BlacklistedTokensManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down Expand Up @@ -33,6 +33,7 @@ var BlacklistedTokensManager = function (options) {
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
3 changes: 2 additions & 1 deletion src/management/ClientGrantsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down Expand Up @@ -35,6 +35,7 @@ var ClientGrantsManager = function (options) {
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
3 changes: 2 additions & 1 deletion src/management/ClientsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down Expand Up @@ -38,6 +38,7 @@ var ClientsManager = function (options) {
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
2 changes: 1 addition & 1 deletion src/management/ConnectionsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down
3 changes: 2 additions & 1 deletion src/management/DeviceCredentialsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down Expand Up @@ -39,6 +39,7 @@ var DeviceCredentialsManager = function (options) {
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
3 changes: 2 additions & 1 deletion src/management/EmailProviderManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down Expand Up @@ -39,6 +39,7 @@ var EmailProviderManager = function (options) {
* @type {Object}
*/
var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
5 changes: 3 additions & 2 deletions src/management/JobsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Promise = require('bluebird');
var fs = require('fs');

var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand Down Expand Up @@ -38,6 +38,7 @@ var JobsManager = function (options){
}

var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down Expand Up @@ -144,7 +145,7 @@ JobsManager.prototype.importUsers = function (data, cb) {
connection_id: data.connection_id
}
}, function (err, res) {


// `superagent` uses the error parameter in callback on http errors.
// the following code is intended to keep that behaviour (https://github.com/visionmedia/superagent/blob/master/lib/node/response.js#L170)
Expand Down
2 changes: 1 addition & 1 deletion src/management/LogsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down
2 changes: 1 addition & 1 deletion src/management/ResourceServersManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');

/**
Expand Down
2 changes: 1 addition & 1 deletion src/management/RulesManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var utils = require('../utils');


Expand Down
3 changes: 2 additions & 1 deletion src/management/StatsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand Down Expand Up @@ -33,6 +33,7 @@ var StatsManager = function (options){
}

var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
3 changes: 2 additions & 1 deletion src/management/TenantManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand Down Expand Up @@ -33,6 +33,7 @@ var TenantManager = function (options){
}

var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
3 changes: 2 additions & 1 deletion src/management/TicketsManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand All @@ -22,6 +22,7 @@ var TicketsManager = function (options){
}

var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
3 changes: 2 additions & 1 deletion src/management/UsersManager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var RestClient = require('rest-facade').Client;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;


/**
Expand Down Expand Up @@ -33,6 +33,7 @@ var UsersManager = function (options){
}

var clientOptions = {
errorFormatter: { message: 'message', name: 'error' },
headers: options.headers,
query: { repeatParams: false }
};
Expand Down
2 changes: 1 addition & 1 deletion src/management/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var util = require('util');
var pkg = require('../../package.json');
var utils = require('../utils');
var jsonToBase64 = utils.jsonToBase64;
var ArgumentError = require('../exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;

// Managers.
var ClientsManager = require('./ClientsManager');
Expand Down
2 changes: 1 addition & 1 deletion test/auth/authentication-client.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var expect = require('chai').expect;

var ArgumentError = require('../../src/exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;

var AuthenticationClient = require('../../src/auth');
var OAuthAuthenticator = require('../../src/auth/OAuthAuthenticator');
Expand Down
2 changes: 1 addition & 1 deletion test/auth/database-auth.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var DOMAIN = 'tenant.auth0.com';
var API_URL = 'https://' + DOMAIN;
var CLIENT_ID = 'TEST_CLIENT_ID';

var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var Authenticator = require(SRC_DIR + '/auth/DatabaseAuthenticator');
var OAuth = require(SRC_DIR + '/auth/OAuthAuthenticator');

Expand Down
5 changes: 2 additions & 3 deletions test/auth/oauth.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var API_URL = 'https://' + DOMAIN;
var CLIENT_ID = 'TEST_CLIENT_ID';
var CLIENT_SECRET = 'TEST_CLIENT_SECRET';

var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var Authenticator = require(SRC_DIR + '/auth/OAuthAuthenticator');

var validOptions = {
Expand Down Expand Up @@ -560,8 +560,7 @@ describe('OAuthAuthenticator', function () {

var request = nock(API_URL)
.post(path, function (body) {
return body.client_id === CLIENT_ID;
return body.client_secret === CLIENT_SECRET;
return body.client_id === CLIENT_ID && body.client_secret === CLIENT_SECRET;
})
.reply(200);

Expand Down
2 changes: 1 addition & 1 deletion test/auth/passwordless.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var DOMAIN = 'tenant.auth0.com';
var API_URL = 'https://' + DOMAIN;
var CLIENT_ID = 'TEST_CLIENT_ID';

var ArgumentError = require(SRC_DIR + '/exceptions').ArgumentError;
var ArgumentError = require('rest-facade').ArgumentError;
var Authenticator = require(SRC_DIR + '/auth/PasswordlessAuthenticator');
var OAuth = require(SRC_DIR + '/auth/OAuthAuthenticator');

Expand Down
Loading

0 comments on commit f2ed9a6

Please sign in to comment.