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

Migrate to ES6 #304

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
c0da187
chore(es6): Migrate src/utils.js to ES6
vikaspotluri123 Oct 2, 2018
903c46f
chore(docs): fix successfull [sic] typo
vikaspotluri123 Oct 2, 2018
e620a2e
chore(es6): Migrate src/Auth0RestClient.js
vikaspotluri123 Oct 2, 2018
dee0304
chore(es6): Migrate src/RetryRestClient.js
vikaspotluri123 Oct 2, 2018
9a9ccf6
chore(es6): Migrate src/auth/DatabaseAuthenticator.js
vikaspotluri123 Oct 2, 2018
1d1f72f
chore(es6): Migrate src/auth/index.js
vikaspotluri123 Oct 2, 2018
7b0e38e
chore(es6): Migrate src/auth/OAuthAuthenticator.js
vikaspotluri123 Oct 2, 2018
ca8ff28
chore(es6): Migrate src/auth/OAuthWithIDTokenValidation.js
vikaspotluri123 Oct 2, 2018
9736ffe
chore(es6): Migrate src/auth/PasswordlessAuthentication.js
vikaspotluri123 Oct 2, 2018
6848b5e
chore(es6): Migrate src/auth/TokensManager.js
vikaspotluri123 Oct 2, 2018
7afeca4
chore(es6): Migrate src/auth/UserManager.js
vikaspotluri123 Oct 2, 2018
e7e479c
chore(deps): remove object.assign
vikaspotluri123 Oct 2, 2018
12e98d8
chore(node): specify minimum v6
vikaspotluri123 Oct 2, 2018
81c22e9
chore(es6): Migrate src/management/BlacklistedTokensManager.js
vikaspotluri123 Oct 2, 2018
22a435d
chore(es6): Migrate src/management/ClientGrantsManager.js
vikaspotluri123 Oct 2, 2018
a1f7dd1
chore(es6): Migrate src/management/ClientGrantsManager.js
vikaspotluri123 Oct 2, 2018
f28d067
chore(es6): Migrate src/management/ClientGrantsManager.js
vikaspotluri123 Oct 2, 2018
0a66bf4
chore(es6): Migrate src/management/ClientsManager.js
vikaspotluri123 Oct 2, 2018
8550e91
chore(es6): Migrate src/management/ConnectionsManager.js
vikaspotluri123 Oct 2, 2018
fe58b38
chore(es6): Migrate src/management/DeviceCredentialsManager.js
vikaspotluri123 Oct 2, 2018
8d13146
chore(es6): Migrate src/management/EmailProviderManager.js
vikaspotluri123 Oct 2, 2018
705dc78
chore(es6): Migrate src/management/EmailTemplatesManager.js
vikaspotluri123 Oct 2, 2018
03145bb
chore(es6): Migrate src/management/GuardianManager.js
vikaspotluri123 Oct 2, 2018
2559a02
chore(es6): Migrate src/management/index.js
vikaspotluri123 Oct 2, 2018
2609ae6
chore(es6): Migrate src/management/JobsManager.js
vikaspotluri123 Oct 2, 2018
d8cbe17
chore(es6): Migrate src/management/LogsManager.js
vikaspotluri123 Oct 2, 2018
5532333
chore(es6): Migrate src/management/ManagementTokenProvider.js
vikaspotluri123 Oct 2, 2018
256e180
chore(es6): Migrate src/management/ResourceServersManager.js
vikaspotluri123 Oct 2, 2018
856201c
chore(es6): Migrate src/management/RulesConfigsManager.js
vikaspotluri123 Oct 2, 2018
9bbf850
chore(es6): Migrate src/management/RulesManager.js
vikaspotluri123 Oct 2, 2018
b98093d
chore(es6): Migrate src/management/StatsManager.js
vikaspotluri123 Oct 2, 2018
0b80183
chore(es6): Migrate src/management/TenantManager.js
vikaspotluri123 Oct 2, 2018
3812212
chore(deps): remove dependency on bluebird
vikaspotluri123 Oct 2, 2018
f946ae1
:bug: prefer Object.assign over destructuring Object
vikaspotluri123 Oct 2, 2018
1f0c22e
chore(es6): Migrate src/management/TicketsManager.js
vikaspotluri123 Oct 2, 2018
9fc45d2
chore(es6): Migrate src/management/UsersManager.js
vikaspotluri123 Oct 2, 2018
e6e6c95
chore(docs): clean up typos
vikaspotluri123 Oct 2, 2018
99aa91d
chore(deps): remove bluebird from deps
vikaspotluri123 Oct 2, 2018
514c463
update lockfile
vikaspotluri123 Oct 2, 2018
e118adc
chore(tests): use proxy function for class instantiation tests
vikaspotluri123 Oct 2, 2018
61bcc6d
chore(tests): use proxy function for class instantiation tests 2/2
vikaspotluri123 Oct 2, 2018
967595a
:bug: fix variable reinit
vikaspotluri123 Oct 2, 2018
fa68d6d
chore(tests): fix tests broken by loss of `this`
vikaspotluri123 Oct 2, 2018
8463faf
:bug: readd bluebird
vikaspotluri123 Oct 2, 2018
8776b3f
fix(tests): TokensManager bug fixes
vikaspotluri123 Oct 2, 2018
23fb9d0
fix(tests): use more abstract verification of promise return
vikaspotluri123 Oct 2, 2018
e77c1df
fix(test-runner): don't watch for changes
vikaspotluri123 Oct 2, 2018
c784228
Fix Promise checking in tests
vikaspotluri123 Oct 3, 2018
d1b6082
chore(deps): make bluebird a dev dependency
vikaspotluri123 Oct 4, 2018
9643a7e
Merge branch 'master' into es6
vikaspotluri123 Oct 4, 2018
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
19 changes: 13 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
"version": "2.13.0",
"description": "SDK for Auth0 API v2",
"main": "src/index.js",
"files": ["src"],
"files": [
"src"
],
"engines": {
"node": ">= 6"
},
"scripts": {
"test": "mocha -R spec $(find ./test -name *.tests.js)",
"test:ci":
"istanbul cover _mocha --report lcovonly -R $(find ./test -name *.tests.js) -- -R mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
"test:ci": "istanbul cover _mocha --report lcovonly -R $(find ./test -name *.tests.js) -- -R mocha-multi --reporter-options spec=-,mocha-junit-reporter=-",
"test:coverage": "codecov",
"test:watch": "NODE_ENV=test mocha --timeout 5000 $(find ./test -name *.tests.js) --watch",
"jsdoc:generate": "jsdoc --configure .jsdoc.json --verbose",
Expand All @@ -21,24 +25,27 @@
"type": "git",
"url": "https://github.com/auth0/node-auth0"
},
"keywords": ["auth0", "api"],
"keywords": [
"auth0",
"api"
],
"author": "Auth0",
"license": "MIT",
"bugs": {
"url": "https://github.com/auth0/node-auth0/issues"
},
"homepage": "https://github.com/auth0/node-auth0",
"dependencies": {
"bluebird": "^2.10.2",
"es6-promisify": "^6.0.0",
"jsonwebtoken": "^8.3.0",
"jwks-rsa": "^1.3.0",
"lru-memoizer": "^1.11.1",
"object.assign": "^4.0.4",
"request": "^2.83.0",
"rest-facade": "^1.10.1",
"retry": "^0.10.1"
},
"devDependencies": {
"bluebird": "^2.10.2",
"chai": "^2.2.0",
"codecov": "^2.2.0",
"husky": "^0.14.3",
Expand Down
85 changes: 42 additions & 43 deletions src/Auth0RestClient.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,71 @@
var RestClient = require('rest-facade').Client;
var Promise = require('bluebird');
var ArgumentError = require('rest-facade').ArgumentError;
const { ArgumentError, Client: RestClient } = require('rest-facade');

var Auth0RestClient = function(resourceUrl, options, provider) {
if (resourceUrl === null || resourceUrl === undefined) {
throw new ArgumentError('Must provide a Resource Url');
}
class Auth0RestClient {
constructor(resourceUrl, options, provider) {
if (resourceUrl === null || resourceUrl === undefined) {
throw new ArgumentError('Must provide a Resource Url');
}

if ('string' !== typeof resourceUrl || resourceUrl.length === 0) {
throw new ArgumentError('The provided Resource Url is invalid');
}
if ('string' !== typeof resourceUrl || resourceUrl.length === 0) {
throw new ArgumentError('The provided Resource Url is invalid');
}

if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide options');
}
if (options === null || typeof options !== 'object') {
throw new ArgumentError('Must provide options');
}

this.options = options;
this.provider = provider;
this.restClient = new RestClient(resourceUrl, options);
this.options = options;
this.provider = provider;
this.restClient = new RestClient(resourceUrl, options);
}

this.wrappedProvider = function(method, args) {
wrappedProvider(method, args) {
if (!this.provider) {
return this.restClient[method].apply(this.restClient, args);
}

var callback;
let callback;
if (args && args[args.length - 1] instanceof Function) {
callback = args[args.length - 1];
}

var self = this;
return this.provider
.getAccessToken()
.then(function(access_token) {
self.options.headers['Authorization'] = 'Bearer ' + access_token;
return self.restClient[method].apply(self.restClient, args);
.then(access_token => {
this.options.headers.Authorization = `Bearer ${access_token}`;
return this.restClient[method].apply(this.restClient, args);
})
.catch(function(err) {
.catch(err => {
if (callback) {
return callback(err);
}
return Promise.reject(err);
});
};
};
}

Auth0RestClient.prototype.getAll = function(/* [params], [callback] */) {
return this.wrappedProvider('getAll', arguments);
};
getAll(...args /* [params], [callback] */) {
return this.wrappedProvider('getAll', args);
}

Auth0RestClient.prototype.get = function(/* [params], [callback] */) {
return this.wrappedProvider('get', arguments);
};
get(...args /* [params], [callback] */) {
return this.wrappedProvider('get', args);
}

Auth0RestClient.prototype.create = function(/* [params], [callback] */) {
return this.wrappedProvider('create', arguments);
};
create(...args /* [params], [callback] */) {
return this.wrappedProvider('create', args);
}

Auth0RestClient.prototype.patch = function(/* [params], [callback] */) {
return this.wrappedProvider('patch', arguments);
};
patch(...args /* [params], [callback] */) {
return this.wrappedProvider('patch', args);
}

Auth0RestClient.prototype.update = function(/* [params], [callback] */) {
return this.wrappedProvider('update', arguments);
};
update(...args /* [params], [callback] */) {
return this.wrappedProvider('update', args);
}

Auth0RestClient.prototype.delete = function(/* [params], [callback] */) {
return this.wrappedProvider('delete', arguments);
};
delete(...args /* [params], [callback] */) {
return this.wrappedProvider('delete', args);
}
}

module.exports = Auth0RestClient;
Loading