auth0 2.36.0 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +554 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -15
  4. package/src/Auth0RestClient.js +72 -71
  5. package/src/RetryRestClient.js +78 -81
  6. package/src/auth/DatabaseAuthenticator.js +242 -259
  7. package/src/auth/OAUthWithIDTokenValidation.js +99 -103
  8. package/src/auth/OAuthAuthenticator.js +325 -344
  9. package/src/auth/PasswordlessAuthenticator.js +237 -252
  10. package/src/auth/TokensManager.js +231 -246
  11. package/src/auth/UsersManager.js +149 -160
  12. package/src/auth/idToken.js +22 -19
  13. package/src/auth/index.js +510 -581
  14. package/src/errors.js +23 -23
  15. package/src/index.js +3 -2
  16. package/src/management/ActionsManager.js +503 -585
  17. package/src/management/BlacklistedTokensManager.js +77 -84
  18. package/src/management/BrandingManager.js +141 -163
  19. package/src/management/ClientGrantsManager.js +132 -145
  20. package/src/management/ClientsManager.js +145 -161
  21. package/src/management/ConnectionsManager.js +215 -204
  22. package/src/management/CustomDomainsManager.js +140 -157
  23. package/src/management/DeviceCredentialsManager.js +95 -111
  24. package/src/management/EmailProviderManager.js +110 -128
  25. package/src/management/EmailTemplatesManager.js +96 -112
  26. package/src/management/GrantsManager.js +94 -101
  27. package/src/management/GuardianManager.js +381 -455
  28. package/src/management/HooksManager.js +283 -325
  29. package/src/management/JobsManager.js +310 -343
  30. package/src/management/LogStreamsManager.js +142 -158
  31. package/src/management/LogsManager.js +92 -99
  32. package/src/management/ManagementTokenProvider.js +112 -120
  33. package/src/management/MigrationsManager.js +81 -90
  34. package/src/management/OrganizationsManager.js +686 -761
  35. package/src/management/PromptsManager.js +160 -178
  36. package/src/management/ResourceServersManager.js +143 -160
  37. package/src/management/RolesManager.js +323 -369
  38. package/src/management/RulesConfigsManager.js +94 -110
  39. package/src/management/RulesManager.js +154 -176
  40. package/src/management/StatsManager.js +87 -103
  41. package/src/management/TenantManager.js +81 -97
  42. package/src/management/TicketsManager.js +107 -115
  43. package/src/management/UserBlocksManager.js +135 -162
  44. package/src/management/UsersManager.js +729 -852
  45. package/src/management/index.js +3094 -3619
  46. package/src/utils.js +31 -60
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth0",
3
- "version": "2.36.0",
3
+ "version": "2.38.0",
4
4
  "description": "SDK for Auth0 API v2",
5
5
  "main": "src/index.js",
6
6
  "sideEffects": false,
@@ -8,18 +8,21 @@
8
8
  "src"
9
9
  ],
10
10
  "scripts": {
11
- "test": "mocha --reporter spec ./test/**/*.tests.js ./test/*.tests.js",
11
+ "test": "mocha --reporter spec './test/**/*.tests.js'",
12
12
  "test:ci": "nyc npm run test -- --forbid-only --reporter mocha-junit-reporter",
13
13
  "test:coverage": "codecov",
14
- "test:watch": "cross-env NODE_ENV=test mocha --timeout 5000 ./test/**/*.tests.js ./test/*.tests.js --watch",
14
+ "test:watch": "cross-env NODE_ENV=test mocha --timeout 5000 './test/**/*.tests.js' './test/*.tests.js' --watch",
15
15
  "jsdoc:generate": "jsdoc --configure .jsdoc.json --verbose",
16
- "version": "node ./scripts/release.js",
17
- "precommit": "pretty-quick --staged"
16
+ "precommit": "pretty-quick --staged",
17
+ "lint": "eslint ."
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
21
  "url": "https://github.com/auth0/node-auth0"
22
22
  },
23
+ "engines": {
24
+ "node": ">=8.3.0"
25
+ },
23
26
  "keywords": [
24
27
  "auth0",
25
28
  "api"
@@ -31,34 +34,38 @@
31
34
  },
32
35
  "homepage": "https://github.com/auth0/node-auth0",
33
36
  "dependencies": {
34
- "axios": "^0.21.1",
35
- "es6-promisify": "^6.1.1",
37
+ "axios": "^0.24.0",
36
38
  "form-data": "^3.0.1",
37
39
  "jsonwebtoken": "^8.5.1",
38
40
  "jwks-rsa": "^1.12.1",
39
41
  "lru-memoizer": "^2.1.4",
40
- "rest-facade": "^1.13.0",
42
+ "rest-facade": "^1.16.3",
41
43
  "retry": "^0.13.1"
42
44
  },
43
45
  "devDependencies": {
44
46
  "chai": "^4.2.0",
45
47
  "codecov": "^3.7.2",
46
48
  "cross-env": "^5.2.0",
49
+ "eslint": "^8.1.0",
50
+ "eslint-config-prettier": "^8.3.0",
51
+ "eslint-plugin-jsdoc": "^37.0.3",
52
+ "eslint-plugin-node": "^11.1.0",
53
+ "eslint-plugin-prettier": "^4.0.0",
54
+ "eslint-plugin-promise": "^5.1.1",
47
55
  "husky": "^3.0.1",
48
- "jsdoc": "^3.6.3",
56
+ "jsdoc": "^3.6.7",
49
57
  "json-loader": "^0.5.7",
50
58
  "jws": "^3.2.2",
51
59
  "minami": "^1.2.3",
52
- "mocha": "^6.2.0",
53
- "mocha-junit-reporter": "^1.23.1",
54
- "moment": "^2.24.0",
60
+ "mocha": "^8.4.0",
61
+ "mocha-junit-reporter": "^2.0.0",
55
62
  "nock": "^10.0.6",
56
63
  "nyc": "^14.1.1",
57
64
  "pem": "^1.14.2",
58
- "prettier": "^1.18.2",
65
+ "prettier": "2.4.1",
59
66
  "pretty-quick": "^1.11.1",
60
- "proxyquire": "^2.1.1",
61
- "sinon": "^9.0.3",
67
+ "proxyquire": "^2.1.3",
68
+ "sinon": "^11.1.2",
62
69
  "string-replace-webpack-plugin": "0.1.3",
63
70
  "webpack": "^4.36.1"
64
71
  }
@@ -1,89 +1,90 @@
1
- var RestClient = require('rest-facade').Client;
2
- var ArgumentError = require('rest-facade').ArgumentError;
1
+ const RestClient = require('rest-facade').Client;
2
+ const { ArgumentError } = require('rest-facade');
3
3
 
4
- var utils = require('./utils');
5
- var SanitizedError = require('./errors').SanitizedError;
4
+ const utils = require('./utils');
5
+ const { SanitizedError } = require('./errors');
6
6
 
7
- var Auth0RestClient = function(resourceUrl, options, provider) {
8
- if (resourceUrl === null || resourceUrl === undefined) {
9
- throw new ArgumentError('Must provide a Resource Url');
10
- }
11
-
12
- if ('string' !== typeof resourceUrl || resourceUrl.length === 0) {
13
- throw new ArgumentError('The provided Resource Url is invalid');
14
- }
7
+ class Auth0RestClient {
8
+ constructor(resourceUrl, options, provider) {
9
+ if (resourceUrl === null || resourceUrl === undefined) {
10
+ throw new ArgumentError('Must provide a Resource Url');
11
+ }
15
12
 
16
- if (options === null || typeof options !== 'object') {
17
- throw new ArgumentError('Must provide options');
18
- }
13
+ if ('string' !== typeof resourceUrl || resourceUrl.length === 0) {
14
+ throw new ArgumentError('The provided Resource Url is invalid');
15
+ }
19
16
 
20
- options.errorCustomizer = options.errorCustomizer || SanitizedError;
21
- options.errorFormatter = options.errorFormatter || { message: 'message', name: 'error' };
17
+ if (options === null || typeof options !== 'object') {
18
+ throw new ArgumentError('Must provide options');
19
+ }
22
20
 
23
- this.options = options;
24
- this.provider = provider;
25
- this.restClient = new RestClient(resourceUrl, options);
21
+ options.errorCustomizer = options.errorCustomizer || SanitizedError;
22
+ options.errorFormatter = options.errorFormatter || { message: 'message', name: 'error' };
23
+
24
+ this.options = options;
25
+ this.provider = provider;
26
+ this.restClient = new RestClient(resourceUrl, options);
27
+
28
+ this.wrappedProvider = function (method, args) {
29
+ if (!this.provider) {
30
+ return this.restClient[method](...args);
31
+ }
32
+
33
+ let callback;
34
+ if (args && args[args.length - 1] instanceof Function) {
35
+ callback = args[args.length - 1];
36
+ }
37
+
38
+ return this.provider
39
+ .getAccessToken()
40
+ .then((access_token) => {
41
+ this.restClient.options.headers['Authorization'] = `Bearer ${access_token}`;
42
+ return this.restClient[method](...args);
43
+ })
44
+ .catch((err) => {
45
+ if (callback) {
46
+ return callback(err);
47
+ }
48
+ throw err;
49
+ });
50
+ };
51
+ }
26
52
 
27
- this.wrappedProvider = function(method, args) {
28
- if (!this.provider) {
29
- return this.restClient[method].apply(this.restClient, args);
30
- }
53
+ getAll(...args) {
54
+ return this.wrappedProvider('getAll', args);
55
+ }
31
56
 
32
- var callback;
33
- if (args && args[args.length - 1] instanceof Function) {
34
- callback = args[args.length - 1];
57
+ get(params, callback) {
58
+ if (typeof params === 'object' && params.id) {
59
+ params.id = utils.maybeDecode(`${params.id}`);
35
60
  }
36
-
37
- var self = this;
38
- return this.provider
39
- .getAccessToken()
40
- .then(function(access_token) {
41
- self.restClient.options.headers['Authorization'] = 'Bearer ' + access_token;
42
- return self.restClient[method].apply(self.restClient, args);
43
- })
44
- .catch(function(err) {
45
- if (callback) {
46
- return callback(err);
47
- }
48
- return Promise.reject(err);
49
- });
50
- };
51
- };
52
-
53
- Auth0RestClient.prototype.getAll = function(params, callback) {
54
- return this.wrappedProvider('getAll', arguments);
55
- };
56
-
57
- Auth0RestClient.prototype.get = function(params, callback) {
58
- if (typeof params === 'object' && params.id) {
59
- params.id = utils.maybeDecode(`${params.id}`);
61
+ return this.wrappedProvider('get', [...[params, callback].filter(Boolean)]);
60
62
  }
61
- return this.wrappedProvider('get', [...[params, callback].filter(Boolean)]);
62
- };
63
63
 
64
- Auth0RestClient.prototype.create = function(/* [params], [callback] */) {
65
- return this.wrappedProvider('create', arguments);
66
- };
64
+ create(...args) {
65
+ return this.wrappedProvider('create', args);
66
+ }
67
67
 
68
- Auth0RestClient.prototype.patch = function(params, callback) {
69
- if (typeof params === 'object' && params.id) {
70
- params.id = utils.maybeDecode(`${params.id}`);
68
+ patch(params, ...restOfArgs) {
69
+ if (typeof params === 'object' && params.id) {
70
+ params.id = utils.maybeDecode(`${params.id}`);
71
+ }
72
+ return this.wrappedProvider('patch', [params, ...restOfArgs]);
71
73
  }
72
- return this.wrappedProvider('patch', arguments);
73
- };
74
74
 
75
- Auth0RestClient.prototype.update = function(params, callback) {
76
- if (typeof params === 'object' && params.id) {
77
- params.id = utils.maybeDecode(`${params.id}`);
75
+ update(params, ...restOfArgs) {
76
+ if (typeof params === 'object' && params.id) {
77
+ params.id = utils.maybeDecode(`${params.id}`);
78
+ }
79
+ return this.wrappedProvider('update', [params, ...restOfArgs]);
78
80
  }
79
- return this.wrappedProvider('update', arguments);
80
- };
81
81
 
82
- Auth0RestClient.prototype.delete = function(params, callback) {
83
- if (typeof params === 'object' && params.id) {
84
- params.id = utils.maybeDecode(`${params.id}`);
82
+ delete(params, ...restOfArgs) {
83
+ if (typeof params === 'object' && params.id) {
84
+ params.id = utils.maybeDecode(`${params.id}`);
85
+ }
86
+ return this.wrappedProvider('delete', [params, ...restOfArgs]);
85
87
  }
86
- return this.wrappedProvider('delete', arguments);
87
- };
88
+ }
88
89
 
89
90
  module.exports = Auth0RestClient;
@@ -1,108 +1,105 @@
1
- var retry = require('retry');
2
- var ArgumentError = require('rest-facade').ArgumentError;
1
+ const retry = require('retry');
2
+ const { ArgumentError } = require('rest-facade');
3
3
 
4
- var DEFAULT_OPTIONS = {
4
+ const DEFAULT_OPTIONS = {
5
5
  maxRetries: 3,
6
6
  enabled: true,
7
- randomize: true
7
+ randomize: true,
8
8
  };
9
9
 
10
10
  /**
11
- * @class RetryRestClient
12
11
  * Wrapper Rest Client that adds Retry functionality when requests are failing due to rate limiting (status code 429).
13
- * @constructor
14
- * @memberOf module:management
15
- * @param {Object} restClient RestClient.
16
- * @param {Object} [options] Options for the RetryRestClient.
17
- * @param {Object} [options.enabled:true] Enabled or Disable Retry Policy functionality.
18
- * @param {Number} [options.maxRetries=10] The maximum amount of times to retry the operation. Default is 10.
19
- * @param {*} [options.*] Any options that are available in https://github.com/tim-kos/node-retry#retryoperationoptions
20
12
  */
21
- var RetryRestClient = function(restClient, options) {
22
- if (restClient === null || typeof restClient !== 'object') {
23
- throw new ArgumentError('Must provide RestClient');
13
+ class RetryRestClient {
14
+ /**
15
+ * @param {object} restClient RestClient.
16
+ * @param {object} [options] Options for the RetryRestClient. It includes all properties from https://github.com/tim-kos/node-retry#retryoperationoptions
17
+ * @param {object} [options.enabled=true] Enabled or Disable Retry Policy functionality.
18
+ * @param {number} [options.maxRetries=3] The maximum amount of times to retry the operation.
19
+ */
20
+ constructor(restClient, options) {
21
+ if (restClient === null || typeof restClient !== 'object') {
22
+ throw new ArgumentError('Must provide RestClient');
23
+ }
24
+
25
+ const params = Object.assign({}, DEFAULT_OPTIONS, options);
26
+
27
+ if (typeof params.enabled !== 'boolean') {
28
+ throw new ArgumentError('Must provide enabled boolean value');
29
+ }
30
+
31
+ if (typeof params.maxRetries !== 'number' || params.maxRetries <= 0) {
32
+ throw new ArgumentError('Must provide maxRetries as a positive number');
33
+ }
34
+
35
+ this.restClient = restClient;
36
+ this.enabled = params.enabled;
37
+ this.retryOptions = Object.assign({ retries: params.maxRetries }, params);
24
38
  }
25
39
 
26
- var params = Object.assign({}, DEFAULT_OPTIONS, options);
27
-
28
- if (typeof params.enabled !== 'boolean') {
29
- throw new ArgumentError('Must provide enabled boolean value');
40
+ getAll(...args) {
41
+ return this.invoke('getAll', args);
30
42
  }
31
43
 
32
- if (typeof params.maxRetries !== 'number' || params.maxRetries <= 0) {
33
- throw new ArgumentError('Must provide maxRetries as a positive number');
44
+ get(...args) {
45
+ return this.invoke('get', args);
34
46
  }
35
47
 
36
- this.restClient = restClient;
37
- this.enabled = params.enabled;
38
- this.retryOptions = Object.assign({ retries: params.maxRetries }, params);
39
- };
40
-
41
- RetryRestClient.prototype.getAll = function(/* [params], [callback] */) {
42
- return this.invoke('getAll', arguments);
43
- };
44
-
45
- RetryRestClient.prototype.get = function(/* [params], [callback] */) {
46
- return this.invoke('get', arguments);
47
- };
48
-
49
- RetryRestClient.prototype.create = function(/* [params], [callback] */) {
50
- return this.invoke('create', arguments);
51
- };
52
-
53
- RetryRestClient.prototype.patch = function(/* [params], [callback] */) {
54
- return this.invoke('patch', arguments);
55
- };
48
+ create(...args) {
49
+ return this.invoke('create', args);
50
+ }
56
51
 
57
- RetryRestClient.prototype.update = function(/* [params], [callback] */) {
58
- return this.invoke('update', arguments);
59
- };
52
+ patch(...args) {
53
+ return this.invoke('patch', args);
54
+ }
60
55
 
61
- RetryRestClient.prototype.delete = function(/* [params], [callback] */) {
62
- return this.invoke('delete', arguments);
63
- };
56
+ update(...args) {
57
+ return this.invoke('update', args);
58
+ }
64
59
 
65
- RetryRestClient.prototype.invoke = function(method, args) {
66
- var cb;
67
- args = Array.prototype.slice.call(args); // convert array-like object to array.
68
- if (args && args[args.length - 1] instanceof Function) {
69
- cb = args[args.length - 1];
70
- args.pop(); // Remove the callback
60
+ delete(...args) {
61
+ return this.invoke('delete', args);
71
62
  }
72
63
 
73
- var promise = this.handleRetry(method, args);
64
+ invoke(method, args) {
65
+ let cb;
66
+ if (args && args[args.length - 1] instanceof Function) {
67
+ cb = args[args.length - 1];
68
+ args.pop(); // Remove the callback
69
+ }
74
70
 
75
- if (cb instanceof Function) {
76
- promise.then(cb.bind(null, null)).catch(cb);
77
- return;
78
- }
71
+ const promise = this.handleRetry(method, args);
79
72
 
80
- return promise;
81
- };
73
+ if (cb instanceof Function) {
74
+ promise.then(cb.bind(null, null)).catch(cb);
75
+ return;
76
+ }
82
77
 
83
- RetryRestClient.prototype.handleRetry = function(method, args) {
84
- if (!this.enabled) {
85
- return this.restClient[method].apply(this.restClient, args);
78
+ return promise;
86
79
  }
87
80
 
88
- var self = this;
89
- return new Promise(function(resolve, reject) {
90
- var operation = retry.operation(self.retryOptions);
91
-
92
- operation.attempt(function() {
93
- self.restClient[method]
94
- .apply(self.restClient, args)
95
- .then(function(body) {
96
- resolve(body);
97
- })
98
- .catch(function(err) {
99
- if (err && err.statusCode === 429 && operation.retry(err)) {
100
- return;
101
- }
102
- reject(err);
103
- });
81
+ handleRetry(method, args) {
82
+ if (!this.enabled) {
83
+ return this.restClient[method](...args);
84
+ }
85
+
86
+ return new Promise((resolve, reject) => {
87
+ const operation = retry.operation(this.retryOptions);
88
+
89
+ operation.attempt(() => {
90
+ this.restClient[method](...args)
91
+ .then((body) => {
92
+ resolve(body);
93
+ })
94
+ .catch((err) => {
95
+ if (err && err.statusCode === 429 && operation.retry(err)) {
96
+ return;
97
+ }
98
+ reject(err);
99
+ });
100
+ });
104
101
  });
105
- });
106
- };
102
+ }
103
+ }
107
104
 
108
105
  module.exports = RetryRestClient;