auth0 2.37.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 +18 -0
  2. package/README.md +33 -11
  3. package/package.json +22 -14
  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 -583
  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 -239
  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 -784
  35. package/src/management/PromptsManager.js +160 -182
  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 -3625
  46. package/src/utils.js +31 -60
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ## [v2.38.0](https://github.com/auth0/node-auth0/tree/v2.38.0) (2022-01-26)
4
+
5
+ [Full Changelog](https://github.com/auth0/node-auth0/compare/v2.37.0...v2.38.0)
6
+
7
+ **Added**
8
+
9
+ - [CAUTH-1274]: feat(attack protection): add breached password detection endpoints [\#676](https://github.com/auth0/node-auth0/pull/676) ([sdwvit](https://github.com/sdwvit))
10
+ - [CAUTH-1272]: feat(attack protection): add suspicious IP throttling endpoints support [\#672](https://github.com/auth0/node-auth0/pull/672) ([sdwvit](https://github.com/sdwvit))
11
+ - [CAUTH-1270]: feat(attack protection): add brute-force-protection endpoints support [\#666](https://github.com/auth0/node-auth0/pull/666) ([sdwvit](https://github.com/sdwvit))
12
+
13
+ **Changed**
14
+
15
+ - refactor to es6 syntax with classes [\#665](https://github.com/auth0/node-auth0/pull/665) ([hornta](https://github.com/hornta))
16
+
17
+ **Fixed**
18
+
19
+ - [SDK-3030] Wrong url when doing assign users with a callback [\#686](https://github.com/auth0/node-auth0/pull/686) ([adamjmcgrath](https://github.com/adamjmcgrath))
20
+
3
21
  ## [v2.37.0](https://github.com/auth0/node-auth0/tree/v2.37.0) (2021-10-14)
4
22
 
5
23
  [Full Changelog](https://github.com/auth0/node-auth0/compare/v2.36.2...v2.37.0)
package/README.md CHANGED
@@ -21,6 +21,10 @@ You can find this library documentation in this [page](https://auth0.github.io/n
21
21
 
22
22
  For more information about [auth0](https://auth0.com) check our [documentation page](https://auth0.com/docs).
23
23
 
24
+ ## Node version support
25
+
26
+ This SDK is tested on the latest Node versions 8, 10, 12 and 14.
27
+
24
28
  ## Authentication API Client
25
29
 
26
30
  This client must be used to access Auth0's [Authentication API](https://auth0.com/docs/api/authentication).
@@ -32,7 +36,7 @@ var AuthenticationClient = require('auth0').AuthenticationClient;
32
36
 
33
37
  var auth0 = new AuthenticationClient({
34
38
  domain: '{YOUR_ACCOUNT}.auth0.com',
35
- clientId: '{OPTIONAL_CLIENT_ID}'
39
+ clientId: '{OPTIONAL_CLIENT_ID}',
36
40
  });
37
41
  ```
38
42
 
@@ -47,7 +51,7 @@ var ManagementClient = require('auth0').ManagementClient;
47
51
 
48
52
  var management = new ManagementClient({
49
53
  token: '{YOUR_API_V2_TOKEN}',
50
- domain: '{YOUR_ACCOUNT}.auth0.com'
54
+ domain: '{YOUR_ACCOUNT}.auth0.com',
51
55
  });
52
56
  ```
53
57
 
@@ -62,7 +66,7 @@ var auth0 = new ManagementClient({
62
66
  domain: '{YOUR_ACCOUNT}.auth0.com',
63
67
  clientId: '{YOUR_NON_INTERACTIVE_CLIENT_ID}',
64
68
  clientSecret: '{YOUR_NON_INTERACTIVE_CLIENT_SECRET}',
65
- scope: 'read:users update:users'
69
+ scope: 'read:users update:users',
66
70
  });
67
71
  ```
68
72
 
@@ -76,15 +80,15 @@ var AuthenticationClient = require('auth0').AuthenticationClient;
76
80
  var auth0 = new AuthenticationClient({
77
81
  domain: '{YOUR_ACCOUNT}.auth0.com',
78
82
  clientId: '{CLIENT_ID}',
79
- clientSecret: '{CLIENT_SECRET}'
83
+ clientSecret: '{CLIENT_SECRET}',
80
84
  });
81
85
 
82
86
  auth0.clientCredentialsGrant(
83
87
  {
84
88
  audience: 'https://{YOUR_ACCOUNT}.auth0.com/api/v2/',
85
- scope: '{MANAGEMENT_API_SCOPES}'
89
+ scope: '{MANAGEMENT_API_SCOPES}',
86
90
  },
87
- function(err, response) {
91
+ function (err, response) {
88
92
  if (err) {
89
93
  // Handle error.
90
94
  }
@@ -101,7 +105,7 @@ Be aware that all methods can be used with promises or callbacks. However, when
101
105
 
102
106
  ```js
103
107
  // Using callbacks.
104
- management.getUsers(function(err, users) {
108
+ management.getUsers(function (err, users) {
105
109
  if (err) {
106
110
  // handle error.
107
111
  }
@@ -111,15 +115,34 @@ management.getUsers(function(err, users) {
111
115
  // Using promises.
112
116
  management
113
117
  .getUsers()
114
- .then(function(users) {
118
+ .then(function (users) {
115
119
  console.log(users);
116
120
  })
117
- .catch(function(err) {
121
+ .catch(function (err) {
118
122
  // Handle error.
119
123
  });
120
124
  ```
125
+
121
126
  ## Typescript
122
- The types for this library are currently maintained by the community at [Definitely Typed](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/auth0). The team is planning taking ownership of this library as discussed in https://github.com/auth0/node-auth0/issues/572. After the team has taken ownership we will remove this net from the Readme.
127
+
128
+ The types for this library are currently maintained by the community at [Definitely Typed](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/auth0). The team is planning taking ownership of this library as discussed in https://github.com/auth0/node-auth0/issues/572. After the team has taken ownership we will remove this net from the Readme.
129
+
130
+ ## Troubleshooting
131
+
132
+ ### Getting `Error: Can't resolve 'superagent-proxy'` when bundling with Webpack
133
+
134
+ We have a dependency on `rest-facade` which `require`s but doesn't include `superagent-proxy`. This SDK doesn't support proxies, so this dependency is not required. To workaround this you can add the following to your `webpack.config.js`:
135
+
136
+ ```
137
+ resolve: {
138
+ alias: {
139
+ 'superagent-proxy': false
140
+ }
141
+ }
142
+ ```
143
+
144
+ Or install `superagent-proxy` yourself.
145
+
123
146
 
124
147
  ## What is Auth0?
125
148
 
@@ -162,5 +185,4 @@ This project is licensed under the MIT license. See the [LICENSE](LICENSE) file
162
185
  [downloads-image]: https://img.shields.io/npm/dm/auth0.svg?style=flat-square
163
186
  [downloads-url]: https://npmjs.org/package/auth0
164
187
 
165
-
166
188
  [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fauth0%2Fnode-auth0.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fauth0%2Fnode-auth0?ref=badge_large)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth0",
3
- "version": "2.37.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,17 +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
- "precommit": "pretty-quick --staged"
16
+ "precommit": "pretty-quick --staged",
17
+ "lint": "eslint ."
17
18
  },
18
19
  "repository": {
19
20
  "type": "git",
20
21
  "url": "https://github.com/auth0/node-auth0"
21
22
  },
23
+ "engines": {
24
+ "node": ">=8.3.0"
25
+ },
22
26
  "keywords": [
23
27
  "auth0",
24
28
  "api"
@@ -30,34 +34,38 @@
30
34
  },
31
35
  "homepage": "https://github.com/auth0/node-auth0",
32
36
  "dependencies": {
33
- "axios": "^0.21.4",
34
- "es6-promisify": "^6.1.1",
37
+ "axios": "^0.24.0",
35
38
  "form-data": "^3.0.1",
36
39
  "jsonwebtoken": "^8.5.1",
37
40
  "jwks-rsa": "^1.12.1",
38
41
  "lru-memoizer": "^2.1.4",
39
- "rest-facade": "^1.13.1",
42
+ "rest-facade": "^1.16.3",
40
43
  "retry": "^0.13.1"
41
44
  },
42
45
  "devDependencies": {
43
46
  "chai": "^4.2.0",
44
47
  "codecov": "^3.7.2",
45
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",
46
55
  "husky": "^3.0.1",
47
- "jsdoc": "^3.6.3",
56
+ "jsdoc": "^3.6.7",
48
57
  "json-loader": "^0.5.7",
49
58
  "jws": "^3.2.2",
50
59
  "minami": "^1.2.3",
51
- "mocha": "^6.2.0",
52
- "mocha-junit-reporter": "^1.23.1",
53
- "moment": "^2.24.0",
60
+ "mocha": "^8.4.0",
61
+ "mocha-junit-reporter": "^2.0.0",
54
62
  "nock": "^10.0.6",
55
63
  "nyc": "^14.1.1",
56
64
  "pem": "^1.14.2",
57
- "prettier": "^1.18.2",
65
+ "prettier": "2.4.1",
58
66
  "pretty-quick": "^1.11.1",
59
- "proxyquire": "^2.1.1",
60
- "sinon": "^9.0.3",
67
+ "proxyquire": "^2.1.3",
68
+ "sinon": "^11.1.2",
61
69
  "string-replace-webpack-plugin": "0.1.3",
62
70
  "webpack": "^4.36.1"
63
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=3] The maximum amount of times to retry the operation. Default is 3.
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;