auth0 2.42.0 → 2.44.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 (34) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +5 -6
  3. package/src/Auth0RestClient.js +32 -2
  4. package/src/management/ActionsManager.js +12 -73
  5. package/src/management/AttackProtectionManager.js +8 -37
  6. package/src/management/BaseManager.js +41 -0
  7. package/src/management/BlacklistedTokensManager.js +4 -32
  8. package/src/management/BrandingManager.js +6 -39
  9. package/src/management/ClientGrantsManager.js +4 -32
  10. package/src/management/ClientsManager.js +7 -37
  11. package/src/management/ConnectionsManager.js +6 -42
  12. package/src/management/CustomDomainsManager.js +5 -37
  13. package/src/management/DeviceCredentialsManager.js +4 -26
  14. package/src/management/EmailProviderManager.js +4 -32
  15. package/src/management/EmailTemplatesManager.js +4 -27
  16. package/src/management/GrantsManager.js +4 -32
  17. package/src/management/GuardianManager.js +13 -86
  18. package/src/management/HooksManager.js +5 -36
  19. package/src/management/JobsManager.js +6 -38
  20. package/src/management/LogStreamsManager.js +4 -31
  21. package/src/management/LogsManager.js +4 -31
  22. package/src/management/MigrationsManager.js +4 -27
  23. package/src/management/OrganizationsManager.js +14 -65
  24. package/src/management/PromptsManager.js +5 -35
  25. package/src/management/ResourceServersManager.js +4 -31
  26. package/src/management/RolesManager.js +6 -42
  27. package/src/management/RulesConfigsManager.js +4 -31
  28. package/src/management/RulesManager.js +4 -31
  29. package/src/management/StatsManager.js +4 -27
  30. package/src/management/TenantManager.js +4 -27
  31. package/src/management/TicketsManager.js +4 -27
  32. package/src/management/UserBlocksManager.js +5 -35
  33. package/src/management/UsersManager.js +16 -91
  34. package/src/management/index.js +6 -0
@@ -1,11 +1,9 @@
1
- const { ArgumentError } = require('rest-facade');
2
- const Auth0RestClient = require('../Auth0RestClient');
3
- const RetryRestClient = require('../RetryRestClient');
1
+ const BaseManager = require('./BaseManager');
4
2
 
5
3
  /**
6
4
  * Abstracts interaction with the stats endpoint.
7
5
  */
8
- class StatsManager {
6
+ class StatsManager extends BaseManager {
9
7
  /**
10
8
  * @param {object} options The client options.
11
9
  * @param {string} options.baseUrl The URL of the API.
@@ -13,23 +11,7 @@ class StatsManager {
13
11
  * @param {object} [options.retry] Retry Policy Config
14
12
  */
15
13
  constructor(options) {
16
- if (options === null || typeof options !== 'object') {
17
- throw new ArgumentError('Must provide manager options');
18
- }
19
-
20
- if (options.baseUrl === null || options.baseUrl === undefined) {
21
- throw new ArgumentError('Must provide a base URL for the API');
22
- }
23
-
24
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
- throw new ArgumentError('The provided base URL is invalid');
26
- }
27
-
28
- const clientOptions = {
29
- errorFormatter: { message: 'message', name: 'error' },
30
- headers: options.headers,
31
- query: { repeatParams: false },
32
- };
14
+ super(options);
33
15
 
34
16
  /**
35
17
  * Provides an abstraction layer for consuming the
@@ -37,12 +19,7 @@ class StatsManager {
37
19
  *
38
20
  * @type {external:RestClient}
39
21
  */
40
- const auth0RestClient = new Auth0RestClient(
41
- `${options.baseUrl}/stats/:type`,
42
- clientOptions,
43
- options.tokenProvider
44
- );
45
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
22
+ this.resource = this._getRestClient('/stats/:type');
46
23
  }
47
24
 
48
25
  /**
@@ -1,11 +1,9 @@
1
- const { ArgumentError } = require('rest-facade');
2
- const Auth0RestClient = require('../Auth0RestClient');
3
- const RetryRestClient = require('../RetryRestClient');
1
+ const BaseManager = require('./BaseManager');
4
2
 
5
3
  /**
6
4
  * Abstracts interaction with the tenant endpoint.
7
5
  */
8
- class TenantManager {
6
+ class TenantManager extends BaseManager {
9
7
  /**
10
8
  * @param {object} options The client options.
11
9
  * @param {string} options.baseUrl The URL of the API.
@@ -13,23 +11,7 @@ class TenantManager {
13
11
  * @param {object} [options.retry] Retry Policy Config
14
12
  */
15
13
  constructor(options) {
16
- if (options === null || typeof options !== 'object') {
17
- throw new ArgumentError('Must provide manager options');
18
- }
19
-
20
- if (options.baseUrl === null || options.baseUrl === undefined) {
21
- throw new ArgumentError('Must provide a base URL for the API');
22
- }
23
-
24
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
- throw new ArgumentError('The provided base URL is invalid');
26
- }
27
-
28
- const clientOptions = {
29
- errorFormatter: { message: 'message', name: 'error' },
30
- headers: options.headers,
31
- query: { repeatParams: false },
32
- };
14
+ super(options);
33
15
 
34
16
  /**
35
17
  * Provides an abstraction layer for consuming the
@@ -37,12 +19,7 @@ class TenantManager {
37
19
  *
38
20
  * @type {external:RestClient}
39
21
  */
40
- const auth0RestClient = new Auth0RestClient(
41
- `${options.baseUrl}/tenants/settings`,
42
- clientOptions,
43
- options.tokenProvider
44
- );
45
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
22
+ this.resource = this._getRestClient('/tenants/settings');
46
23
  }
47
24
 
48
25
  /**
@@ -1,11 +1,9 @@
1
- const { ArgumentError } = require('rest-facade');
2
- const Auth0RestClient = require('../Auth0RestClient');
3
- const RetryRestClient = require('../RetryRestClient');
1
+ const BaseManager = require('./BaseManager');
4
2
 
5
3
  /**
6
4
  * Abstracts interaction with the tickets endpoint.
7
5
  */
8
- class TicketsManager {
6
+ class TicketsManager extends BaseManager {
9
7
  /**
10
8
  * @param {object} options The client options.
11
9
  * @param {string} options.baseUrl The URL of the API.
@@ -13,23 +11,7 @@ class TicketsManager {
13
11
  * @param {object} [options.retry] Retry Policy Config
14
12
  */
15
13
  constructor(options) {
16
- if (options === null || typeof options !== 'object') {
17
- throw new ArgumentError('Must provide manager options');
18
- }
19
-
20
- if (options.baseUrl === null || options.baseUrl === undefined) {
21
- throw new ArgumentError('Must provide a base URL for the API');
22
- }
23
-
24
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
- throw new ArgumentError('The provided base URL is invalid');
26
- }
27
-
28
- const clientOptions = {
29
- errorFormatter: { message: 'message', name: 'error' },
30
- headers: options.headers,
31
- query: { repeatParams: false },
32
- };
14
+ super(options);
33
15
 
34
16
  /**
35
17
  * Provides an abstraction layer for consuming the
@@ -37,12 +19,7 @@ class TicketsManager {
37
19
  *
38
20
  * @type {external:RestClient}
39
21
  */
40
- const auth0RestClient = new Auth0RestClient(
41
- `${options.baseUrl}/tickets/:type`,
42
- clientOptions,
43
- options.tokenProvider
44
- );
45
- this.resource = new RetryRestClient(auth0RestClient, options.retry);
22
+ this.resource = this._getRestClient('/tickets/:type');
46
23
  }
47
24
 
48
25
  /**
@@ -1,11 +1,10 @@
1
1
  const { ArgumentError } = require('rest-facade');
2
- const Auth0RestClient = require('../Auth0RestClient');
3
- const RetryRestClient = require('../RetryRestClient');
2
+ const BaseManager = require('./BaseManager');
4
3
 
5
4
  /**
6
5
  * Abstracts interaction with the user-blocks endpoint.
7
6
  */
8
- class UserBlocksManager {
7
+ class UserBlocksManager extends BaseManager {
9
8
  /**
10
9
  * @param {object} options The client options.
11
10
  * @param {string} options.baseUrl The URL of the API.
@@ -13,40 +12,11 @@ class UserBlocksManager {
13
12
  * @param {object} [options.retry] Retry Policy Config
14
13
  */
15
14
  constructor(options) {
16
- if (options === null || typeof options !== 'object') {
17
- throw new ArgumentError('Must provide manager options');
18
- }
19
-
20
- if (options.baseUrl === null || options.baseUrl === undefined) {
21
- throw new ArgumentError('Must provide a base URL for the API');
22
- }
23
-
24
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
25
- throw new ArgumentError('The provided base URL is invalid');
26
- }
27
-
28
- const clientOptions = {
29
- errorFormatter: { message: 'message', name: 'error' },
30
- headers: options.headers,
31
- query: { repeatParams: false },
32
- };
15
+ super(options);
33
16
 
34
- const userBlocksByIdResource = new Auth0RestClient(
35
- `${options.baseUrl}/user-blocks/:id`,
36
- clientOptions,
37
- options.tokenProvider
38
- );
39
- this.userBlocksById = new RetryRestClient(userBlocksByIdResource, options.retry);
17
+ this.userBlocksById = this._getRestClient('/user-blocks/:id');
40
18
 
41
- const userBlocksByIdentifierResource = new Auth0RestClient(
42
- `${options.baseUrl}/user-blocks`,
43
- clientOptions,
44
- options.tokenProvider
45
- );
46
- this.userBlocksByIdentifier = new RetryRestClient(
47
- userBlocksByIdentifierResource,
48
- options.retry
49
- );
19
+ this.userBlocksByIdentifier = this._getRestClient('/user-blocks');
50
20
  }
51
21
 
52
22
  /**
@@ -1,12 +1,12 @@
1
1
  const { ArgumentError } = require('rest-facade');
2
- const Auth0RestClient = require('../Auth0RestClient');
3
- const RetryRestClient = require('../RetryRestClient');
2
+ const BaseManager = require('./BaseManager');
3
+
4
4
  const { sanitizeArguments } = require('../utils');
5
5
 
6
6
  /**
7
7
  * Abstracts interaction with the users endpoint.
8
8
  */
9
- class UsersManager {
9
+ class UsersManager extends BaseManager {
10
10
  /**
11
11
  * @param {object} options The client options.
12
12
  * @param {string} options.baseUrl The URL of the API.
@@ -14,30 +14,9 @@ class UsersManager {
14
14
  * @param {object} [options.retry] Retry Policy Config
15
15
  */
16
16
  constructor(options) {
17
- if (options === null || typeof options !== 'object') {
18
- throw new ArgumentError('Must provide manager options');
19
- }
20
-
21
- if (options.baseUrl === null || options.baseUrl === undefined) {
22
- throw new ArgumentError('Must provide a base URL for the API');
23
- }
24
-
25
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
26
- throw new ArgumentError('The provided base URL is invalid');
27
- }
17
+ super(options);
28
18
 
29
- const clientOptions = {
30
- errorFormatter: { message: 'message', name: 'error' },
31
- headers: options.headers,
32
- query: { repeatParams: false },
33
- };
34
-
35
- const usersAuth0RestClient = new Auth0RestClient(
36
- `${options.baseUrl}/users/:id`,
37
- clientOptions,
38
- options.tokenProvider
39
- );
40
- this.users = new RetryRestClient(usersAuth0RestClient, options.retry);
19
+ this.users = this._getRestClient('/users/:id');
41
20
 
42
21
  /**
43
22
  * Provides an abstraction layer for consuming the
@@ -46,89 +25,50 @@ class UsersManager {
46
25
  *
47
26
  * @type {external:RestClient}
48
27
  */
49
- const multifactorAuth0RestClient = new Auth0RestClient(
50
- `${options.baseUrl}/users/:id/multifactor/:provider`,
51
- clientOptions,
52
- options.tokenProvider
53
- );
54
- this.multifactor = new RetryRestClient(multifactorAuth0RestClient, options.retry);
28
+ this.multifactor = this._getRestClient('/users/:id/multifactor/:provider');
55
29
 
56
30
  /**
57
31
  * Provides a simple abstraction layer for linking user accounts.
58
32
  *
59
33
  * @type {external:RestClient}
60
34
  */
61
- const identitiesAuth0RestClient = new Auth0RestClient(
62
- `${options.baseUrl}/users/:id/identities/:provider/:user_id`,
63
- clientOptions,
64
- options.tokenProvider
65
- );
66
- this.identities = new RetryRestClient(identitiesAuth0RestClient, options.retry);
35
+ this.identities = this._getRestClient('/users/:id/identities/:provider/:user_id');
67
36
 
68
37
  /**
69
38
  * Provides a simple abstraction layer for user logs
70
39
  *
71
40
  * @type {external:RestClient}
72
41
  */
73
- const userLogsAuth0RestClient = new Auth0RestClient(
74
- `${options.baseUrl}/users/:id/logs`,
75
- clientOptions,
76
- options.tokenProvider
77
- );
78
- this.userLogs = new RetryRestClient(userLogsAuth0RestClient, options.retry);
42
+ this.userLogs = this._getRestClient('/users/:id/logs');
79
43
 
80
44
  /**
81
45
  * Provides an abstraction layer for retrieving Guardian enrollments.
82
46
  *
83
47
  * @type {external:RestClient}
84
48
  */
85
- const enrollmentsAuth0RestClient = new Auth0RestClient(
86
- `${options.baseUrl}/users/:id/enrollments`,
87
- clientOptions,
88
- options.tokenProvider
89
- );
90
- this.enrollments = new RetryRestClient(enrollmentsAuth0RestClient, options.retry);
49
+ this.enrollments = this._getRestClient('/users/:id/enrollments');
91
50
 
92
51
  /**
93
52
  * Provides an abstraction layer for the new "users-by-email" API
94
53
  *
95
54
  * @type {external:RestClient}
96
55
  */
97
- const usersByEmailClient = new Auth0RestClient(
98
- `${options.baseUrl}/users-by-email`,
99
- clientOptions,
100
- options.tokenProvider
101
- );
102
- this.usersByEmail = new RetryRestClient(usersByEmailClient, options.retry);
56
+ this.usersByEmail = this._getRestClient('/users-by-email');
103
57
 
104
58
  /**
105
59
  * Provides an abstraction layer for regenerating Guardian recovery codes.
106
60
  *
107
61
  * @type {external:RestClient}
108
62
  */
109
- const recoveryCodeRegenerationAuth0RestClients = new Auth0RestClient(
110
- `${options.baseUrl}/users/:id/recovery-code-regeneration`,
111
- clientOptions,
112
- options.tokenProvider
113
- );
114
- this.recoveryCodeRegenerations = new RetryRestClient(
115
- recoveryCodeRegenerationAuth0RestClients,
116
- options.retry
117
- );
63
+ this.recoveryCodeRegenerations = this._getRestClient('/users/:id/recovery-code-regeneration');
118
64
 
119
65
  /**
120
66
  * Provides an abstraction layer for invalidating all remembered browsers for MFA.
121
67
  *
122
68
  * @type {external:RestClient}
123
69
  */
124
- const invalidateRememberBrowserAuth0RestClients = new Auth0RestClient(
125
- `${options.baseUrl}/users/:id/multifactor/actions/invalidate-remember-browser`,
126
- clientOptions,
127
- options.tokenProvider
128
- );
129
- this.invalidateRememberBrowsers = new RetryRestClient(
130
- invalidateRememberBrowserAuth0RestClients,
131
- options.retry
70
+ this.invalidateRememberBrowsers = this._getRestClient(
71
+ '/users/:id/multifactor/actions/invalidate-remember-browser'
132
72
  );
133
73
 
134
74
  /**
@@ -136,31 +76,16 @@ class UsersManager {
136
76
  *
137
77
  * @type {external:RestClient}
138
78
  */
139
- const userRolesClient = new Auth0RestClient(
140
- `${options.baseUrl}/users/:id/roles`,
141
- clientOptions,
142
- options.tokenProvider
143
- );
144
- this.roles = new RetryRestClient(userRolesClient, options.retry);
79
+ this.roles = this._getRestClient('/users/:id/roles');
145
80
 
146
81
  /**
147
82
  * Provides an abstraction layer for CRD on permissions directly on a user
148
83
  *
149
84
  * @type {external:RestClient}
150
85
  */
151
- const userPermissionsClient = new Auth0RestClient(
152
- `${options.baseUrl}/users/:id/permissions`,
153
- clientOptions,
154
- options.tokenProvider
155
- );
156
- this.permissions = new RetryRestClient(userPermissionsClient, options.retry);
86
+ this.permissions = this._getRestClient('/users/:id/permissions');
157
87
 
158
- const organizationsClient = new Auth0RestClient(
159
- `${options.baseUrl}/users/:id/organizations`,
160
- clientOptions,
161
- options.tokenProvider
162
- );
163
- this.organizations = new RetryRestClient(organizationsClient, options.retry);
88
+ this.organizations = this._getRestClient('/users/:id/organizations');
164
89
  }
165
90
 
166
91
  /**
@@ -90,6 +90,8 @@ class ManagementClient {
90
90
  * @param {boolean} [options.retry.enabled=true] Enabled or Disable Retry Policy functionality.
91
91
  * @param {number} [options.retry.maxRetries=10] Retry failed requests X times.
92
92
  * @param {object} [options.headers] Additional headers that will be added to the outgoing requests.
93
+ * @param {string} [options.proxy] Add the `superagent-proxy` dependency and specify a proxy url eg 'https://myproxy.com:1234'
94
+ * @param {boolean} [options.includeResponseHeaders] Include the response headers in the payload in the format `{ data, headers }`.
93
95
  */
94
96
  constructor(options) {
95
97
  if (!options || typeof options !== 'object') {
@@ -147,6 +149,8 @@ class ManagementClient {
147
149
  }
148
150
 
149
151
  managerOptions.retry = options.retry;
152
+ managerOptions.includeResponseHeaders = options.includeResponseHeaders;
153
+ managerOptions.proxy = options.proxy;
150
154
 
151
155
  /**
152
156
  * Simple abstraction for performing CRUD operations on the
@@ -523,6 +527,8 @@ class ManagementClient {
523
527
  * });
524
528
  * @param {object} params Client parameters.
525
529
  * @param {string} params.client_id Application client ID.
530
+ * @param {string} params.fields Comma-separated list of fields to include or exclude (based on value provided for include_fields).
531
+ * @param {string} params.include_fields Whether specified fields are to be included (true) or excluded (false).
526
532
  * @param {Function} [cb] Callback function.
527
533
  * @returns {Promise|undefined}
528
534
  */