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
@@ -1,960 +1,837 @@
1
- var ArgumentError = require('rest-facade').ArgumentError;
2
- var Auth0RestClient = require('../Auth0RestClient');
3
- var RetryRestClient = require('../RetryRestClient');
4
- var sanitizeArguments = require('../utils').sanitizeArguments;
1
+ const { ArgumentError } = require('rest-facade');
2
+ const Auth0RestClient = require('../Auth0RestClient');
3
+ const RetryRestClient = require('../RetryRestClient');
4
+ const { sanitizeArguments } = require('../utils');
5
5
 
6
6
  /**
7
- * Simple facade for consuming a REST API endpoint.
8
- * @external RestClient
9
- * @see https://github.com/ngonzalvez/rest-facade
10
- */
11
-
12
- /**
13
- * @class
14
7
  * Abstracts interaction with the users endpoint.
15
- * @constructor
16
- * @memberOf module:management
17
- *
18
- * @param {Object} options The client options.
19
- * @param {String} options.baseUrl The URL of the API.
20
- * @param {Object} [options.headers] Headers to be included in all requests.
21
- * @param {Object} [options.retry] Retry Policy Config
22
8
  */
23
- var UsersManager = function(options) {
24
- if (options === null || typeof options !== 'object') {
25
- throw new ArgumentError('Must provide manager options');
26
- }
27
-
28
- if (options.baseUrl === null || options.baseUrl === undefined) {
29
- throw new ArgumentError('Must provide a base URL for the API');
30
- }
31
-
32
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
33
- throw new ArgumentError('The provided base URL is invalid');
34
- }
35
-
36
- var clientOptions = {
37
- errorFormatter: { message: 'message', name: 'error' },
38
- headers: options.headers,
39
- query: { repeatParams: false }
40
- };
41
-
42
- var usersAuth0RestClient = new Auth0RestClient(
43
- options.baseUrl + '/users/:id',
44
- clientOptions,
45
- options.tokenProvider
46
- );
47
- this.users = new RetryRestClient(usersAuth0RestClient, options.retry);
48
-
9
+ class UsersManager {
49
10
  /**
50
- * Provides an abstraction layer for consuming the
51
- * {@link https://auth0.com/docs/api/v2#!/Users/delete_multifactor_by_provider
52
- * Multifactor Provider endpoint}.
53
- *
54
- * @type {external:RestClient}
11
+ * @param {object} options The client options.
12
+ * @param {string} options.baseUrl The URL of the API.
13
+ * @param {object} [options.headers] Headers to be included in all requests.
14
+ * @param {object} [options.retry] Retry Policy Config
55
15
  */
56
- var multifactorAuth0RestClient = new Auth0RestClient(
57
- options.baseUrl + '/users/:id/multifactor/:provider',
58
- clientOptions,
59
- options.tokenProvider
60
- );
61
- this.multifactor = new RetryRestClient(multifactorAuth0RestClient, options.retry);
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
+ }
28
+
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);
41
+
42
+ /**
43
+ * Provides an abstraction layer for consuming the
44
+ * {@link https://auth0.com/docs/api/v2#!/Users/delete_multifactor_by_provider
45
+ * Multifactor Provider endpoint}.
46
+ *
47
+ * @type {external:RestClient}
48
+ */
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);
55
+
56
+ /**
57
+ * Provides a simple abstraction layer for linking user accounts.
58
+ *
59
+ * @type {external:RestClient}
60
+ */
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);
67
+
68
+ /**
69
+ * Provides a simple abstraction layer for user logs
70
+ *
71
+ * @type {external:RestClient}
72
+ */
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);
79
+
80
+ /**
81
+ * Provides an abstraction layer for retrieving Guardian enrollments.
82
+ *
83
+ * @type {external:RestClient}
84
+ */
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);
91
+
92
+ /**
93
+ * Provides an abstraction layer for the new "users-by-email" API
94
+ *
95
+ * @type {external:RestClient}
96
+ */
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);
103
+
104
+ /**
105
+ * Provides an abstraction layer for regenerating Guardian recovery codes.
106
+ *
107
+ * @type {external:RestClient}
108
+ */
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
+ );
118
+
119
+ /**
120
+ * Provides an abstraction layer for invalidating all remembered browsers for MFA.
121
+ *
122
+ * @type {external:RestClient}
123
+ */
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
132
+ );
133
+
134
+ /**
135
+ * Provides an abstraction layer for CRD on roles for a user
136
+ *
137
+ * @type {external:RestClient}
138
+ */
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);
145
+
146
+ /**
147
+ * Provides an abstraction layer for CRD on permissions directly on a user
148
+ *
149
+ * @type {external:RestClient}
150
+ */
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);
157
+
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);
164
+ }
62
165
 
63
166
  /**
64
- * Provides a simple abstraction layer for linking user accounts.
167
+ * Create a new user.
65
168
  *
66
- * @type {external:RestClient}
67
- */
68
- var identitiesAuth0RestClient = new Auth0RestClient(
69
- options.baseUrl + '/users/:id/identities/:provider/:user_id',
70
- clientOptions,
71
- options.tokenProvider
72
- );
73
- this.identities = new RetryRestClient(identitiesAuth0RestClient, options.retry);
74
-
75
- /**
76
- * Provides a simple abstraction layer for user logs
169
+ * @example
170
+ * management.users.create(data, function (err) {
171
+ * if (err) {
172
+ * // Handle error.
173
+ * }
77
174
  *
78
- * @type {external:RestClient}
175
+ * // User created.
176
+ * });
177
+ * @param {object} data User data.
178
+ * @param {Function} [cb] Callback function.
179
+ * @returns {Promise|undefined}
79
180
  */
80
- var userLogsAuth0RestClient = new Auth0RestClient(
81
- options.baseUrl + '/users/:id/logs',
82
- clientOptions,
83
- options.tokenProvider
84
- );
85
- this.userLogs = new RetryRestClient(userLogsAuth0RestClient, options.retry);
181
+ create(data, cb) {
182
+ if (cb && cb instanceof Function) {
183
+ return this.users.create(data, cb);
184
+ }
86
185
 
87
- /**
88
- * Provides an abstraction layer for retrieving Guardian enrollments.
89
- *
90
- * @type {external:RestClient}
91
- */
92
- var enrollmentsAuth0RestClient = new Auth0RestClient(
93
- options.baseUrl + '/users/:id/enrollments',
94
- clientOptions,
95
- options.tokenProvider
96
- );
97
- this.enrollments = new RetryRestClient(enrollmentsAuth0RestClient, options.retry);
186
+ return this.users.create(data);
187
+ }
98
188
 
99
189
  /**
100
- * Provides an abstraction layer for the new "users-by-email" API
190
+ * Get all users.
191
+ *
192
+ * @example <caption>
193
+ * This method takes an optional object as first argument that may be used to
194
+ * specify pagination settings and the search query. If pagination options are
195
+ * not present, the first page of a limited number of results will be returned.
196
+ * </caption>
197
+ *
198
+ * // Pagination settings.
199
+ * var params = {
200
+ * per_page: 10,
201
+ * page: 0
202
+ * };
101
203
  *
102
- * @type {external:RestClient}
204
+ * management.users.getAll(params, function (err, users) {
205
+ * console.log(users.length);
206
+ * });
207
+ * @param {object} [params] Users params.
208
+ * @param {number} [params.per_page] Number of results per page.
209
+ * @param {number} [params.page] Page number, zero indexed.
210
+ * @param {Function} [cb] Callback function.
211
+ * @returns {Promise|undefined}
103
212
  */
104
- var usersByEmailClient = new Auth0RestClient(
105
- options.baseUrl + '/users-by-email',
106
- clientOptions,
107
- options.tokenProvider
108
- );
109
- this.usersByEmail = new RetryRestClient(usersByEmailClient, options.retry);
213
+ getAll(...args) {
214
+ return this.users.getAll(...args);
215
+ }
110
216
 
111
217
  /**
112
- * Provides an abstraction layer for regenerating Guardian recovery codes.
218
+ * Get Users by an Email Address
219
+ *
220
+ * @example <caption>
221
+ * This method takes a first argument as the Email address to look for
222
+ * users, and uses the /users-by-email API, not the search API
223
+ * </caption>
113
224
  *
114
- * @type {external:RestClient}
225
+ * management.users.getByEmail('email@address', function (err, users) {
226
+ * console.log(users);
227
+ * });
228
+ * @param {string} [email] Email address of user(s) to find
229
+ * @param {object} [options] Additional options to pass to the endpoint
230
+ * @param {string} [options.fields] Comma-separated list of fields to include or exclude in the result
231
+ * @param {boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true.
232
+ * @param {Function} [cb] Callback function.
233
+ * @returns {Promise|undefined}
115
234
  */
116
- var recoveryCodeRegenerationAuth0RestClients = new Auth0RestClient(
117
- options.baseUrl + '/users/:id/recovery-code-regeneration',
118
- clientOptions,
119
- options.tokenProvider
120
- );
121
- this.recoveryCodeRegenerations = new RetryRestClient(
122
- recoveryCodeRegenerationAuth0RestClients,
123
- options.retry
124
- );
235
+ getByEmail(email, options, cb) {
236
+ const { options: sanitizedOptions, cb: sanitizedCb } = sanitizeArguments(options, cb);
237
+
238
+ return this.usersByEmail.getAll({ email, ...sanitizedOptions }, sanitizedCb);
239
+ }
125
240
 
126
241
  /**
127
- * Provides an abstraction layer for invalidating all remembered browsers for MFA.
242
+ * Get a user by its id.
128
243
  *
129
- * @type {external:RestClient}
244
+ * @example
245
+ * management.users.get({ id: USER_ID }, function (err, user) {
246
+ * console.log(user);
247
+ * });
248
+ * @param {object} data The user data object.
249
+ * @param {string} data.id The user id.
250
+ * @param {Function} [cb] Callback function.
251
+ * @returns {Promise|undefined}
130
252
  */
131
- var invalidateRememberBrowserAuth0RestClients = new Auth0RestClient(
132
- options.baseUrl + '/users/:id/multifactor/actions/invalidate-remember-browser',
133
- clientOptions,
134
- options.tokenProvider
135
- );
136
- this.invalidateRememberBrowsers = new RetryRestClient(
137
- invalidateRememberBrowserAuth0RestClients,
138
- options.retry
139
- );
253
+ get(...args) {
254
+ return this.users.get(...args);
255
+ }
140
256
 
141
257
  /**
142
- * Provides an abstraction layer for CRD on roles for a user
258
+ * Update a user by its id.
259
+ *
260
+ * @example
261
+ * var params = { id: USER_ID };
143
262
  *
144
- * @type {external:RestClient}
263
+ * management.users.update(params, data, function (err, user) {
264
+ * if (err) {
265
+ * // Handle error.
266
+ * }
267
+ *
268
+ * // Updated user.
269
+ * console.log(user);
270
+ * });
271
+ * @param {object} params The user parameters.
272
+ * @param {string} params.id The user id.
273
+ * @param {object} data New user data.
274
+ * @param {Function} [cb] Callback function
275
+ * @returns {Promise|undefined}
145
276
  */
146
- var userRolesClient = new Auth0RestClient(
147
- options.baseUrl + '/users/:id/roles',
148
- clientOptions,
149
- options.tokenProvider
150
- );
151
- this.roles = new RetryRestClient(userRolesClient, options.retry);
277
+ update(...args) {
278
+ return this.users.patch(...args);
279
+ }
152
280
 
153
281
  /**
154
- * Provides an abstraction layer for CRD on permissions directly on a user
282
+ * Update the user metadata.
283
+ *
284
+ * @example
285
+ * var params = { id: USER_ID };
286
+ * var metadata = {
287
+ * address: '123th Node.js Street'
288
+ * };
155
289
  *
156
- * @type {external:RestClient}
290
+ * management.users.updateUserMetadata(params, metadata, function (err, user) {
291
+ * if (err) {
292
+ * // Handle error.
293
+ * }
294
+ *
295
+ * // Updated user.
296
+ * console.log(user);
297
+ * });
298
+ * @param {object} params The user data object..
299
+ * @param {string} params.id The user id.
300
+ * @param {object} metadata New user metadata.
301
+ * @param {Function} [cb] Callback function
302
+ * @returns {Promise|undefined}
157
303
  */
158
- var userPermissionsClient = new Auth0RestClient(
159
- options.baseUrl + '/users/:id/permissions',
160
- clientOptions,
161
- options.tokenProvider
162
- );
163
- this.permissions = new RetryRestClient(userPermissionsClient, options.retry);
164
-
165
- var organizationsClient = new Auth0RestClient(
166
- options.baseUrl + '/users/:id/organizations',
167
- clientOptions,
168
- options.tokenProvider
169
- );
170
- this.organizations = new RetryRestClient(organizationsClient, options.retry);
171
- };
172
-
173
- /**
174
- * Create a new user.
175
- *
176
- * @method create
177
- * @memberOf module:management.UsersManager.prototype
178
- *
179
- * @example
180
- * management.users.create(data, function (err) {
181
- * if (err) {
182
- * // Handle error.
183
- * }
184
- *
185
- * // User created.
186
- * });
187
- *
188
- * @param {Object} data User data.
189
- * @param {Function} [cb] Callback function.
190
- *
191
- * @return {Promise|undefined}
192
- */
193
- UsersManager.prototype.create = function(data, cb) {
194
- if (cb && cb instanceof Function) {
195
- return this.users.create(data, cb);
196
- }
197
-
198
- return this.users.create(data);
199
- };
200
-
201
- /**
202
- * Get all users.
203
- *
204
- * @method getAll
205
- * @memberOf module:management.UsersManager.prototype
206
- *
207
- * @example <caption>
208
- * This method takes an optional object as first argument that may be used to
209
- * specify pagination settings and the search query. If pagination options are
210
- * not present, the first page of a limited number of results will be returned.
211
- * </caption>
212
- *
213
- * // Pagination settings.
214
- * var params = {
215
- * per_page: 10,
216
- * page: 0
217
- * };
218
- *
219
- * management.users.getAll(params, function (err, users) {
220
- * console.log(users.length);
221
- * });
222
- *
223
- * @param {Object} [params] Users params.
224
- * @param {Number} [params.per_page] Number of results per page.
225
- * @param {Number} [params.page] Page number, zero indexed.
226
- * @param {Function} [cb] Callback function.
227
- *
228
- * @return {Promise|undefined}
229
- */
230
- UsersManager.prototype.getAll = function(params) {
231
- return this.users.getAll.apply(this.users, arguments);
232
- };
233
-
234
- /**
235
- * Get Users by an Email Address
236
- *
237
- * @method getByEmail
238
- * @memberOf module:management.UsersManager.prototype
239
- *
240
- * @example <caption>
241
- * This method takes a first argument as the Email address to look for
242
- * users, and uses the /users-by-email API, not the search API
243
- * </caption>
244
- *
245
- * management.users.getByEmail('email@address', function (err, users) {
246
- * console.log(users);
247
- * });
248
- *
249
- * @param {String} [email] Email address of user(s) to find
250
- * @param {Object} [options] Additional options to pass to the endpoint
251
- * @param {String} [options.fields] Comma-separated list of fields to include or exclude in the result
252
- * @param {Boolean} [options.include_fields] Whether specified fields are to be included (true) or excluded (false). Defaults to true.
253
- * @param {Function} [cb] Callback function.
254
- *
255
- * @return {Promise|undefined}
256
- */
257
- UsersManager.prototype.getByEmail = function(email, options, cb) {
258
- var { options, cb } = sanitizeArguments(options, cb);
259
-
260
- return this.usersByEmail.getAll({ email, ...options }, cb);
261
- };
304
+ updateUserMetadata(params, metadata, cb) {
305
+ const data = {
306
+ user_metadata: metadata,
307
+ };
262
308
 
263
- /**
264
- * Get a user by its id.
265
- *
266
- * @method get
267
- * @memberOf module:management.UsersManager.prototype
268
- *
269
- * @example
270
- * management.users.get({ id: USER_ID }, function (err, user) {
271
- * console.log(user);
272
- * });
273
- *
274
- * @param {Object} data The user data object.
275
- * @param {String} data.id The user id.
276
- * @param {Function} [cb] Callback function.
277
- *
278
- * @return {Promise|undefined}
279
- */
280
- UsersManager.prototype.get = function() {
281
- return this.users.get.apply(this.users, arguments);
282
- };
283
-
284
- /**
285
- * Update a user by its id.
286
- *
287
- * @method update
288
- * @memberOf module:management.UsersManager.prototype
289
- *
290
- * @example
291
- * var params = { id: USER_ID };
292
- *
293
- * management.users.update(params, data, function (err, user) {
294
- * if (err) {
295
- * // Handle error.
296
- * }
297
- *
298
- * // Updated user.
299
- * console.log(user);
300
- * });
301
- *
302
- * @param {Object} params The user parameters.
303
- * @param {String} params.id The user id.
304
- * @param {Object} data New user data.
305
- * @param {Function} [cb] Callback function
306
- *
307
- * @return {Promise|undefined}
308
- */
309
- UsersManager.prototype.update = function() {
310
- return this.users.patch.apply(this.users, arguments);
311
- };
309
+ if (cb && cb instanceof Function) {
310
+ return this.users.patch(params, data, cb);
311
+ }
312
312
 
313
- /**
314
- * Update the user metadata.
315
- *
316
- * @method updateUserMetadata
317
- * @memberOf module:management.UsersManager.prototype
318
- *
319
- * @example
320
- * var params = { id: USER_ID };
321
- * var metadata = {
322
- * address: '123th Node.js Street'
323
- * };
324
- *
325
- * management.users.updateUserMetadata(params, metadata, function (err, user) {
326
- * if (err) {
327
- * // Handle error.
328
- * }
329
- *
330
- * // Updated user.
331
- * console.log(user);
332
- * });
333
- *
334
- * @param {Object} params The user data object..
335
- * @param {String} params.id The user id.
336
- * @param {Object} metadata New user metadata.
337
- * @param {Function} [cb] Callback function
338
- *
339
- * @return {Promise|undefined}
340
- */
341
- UsersManager.prototype.updateUserMetadata = function(params, metadata, cb) {
342
- var data = {
343
- user_metadata: metadata
344
- };
345
-
346
- if (cb && cb instanceof Function) {
347
- return this.users.patch(params, data, cb);
313
+ return this.users.patch(params, data);
348
314
  }
349
315
 
350
- return this.users.patch(params, data);
351
- };
316
+ /**
317
+ * Update the app metadata.
318
+ *
319
+ * @example
320
+ * var params = { id: USER_ID };
321
+ * var metadata = {
322
+ * foo: 'bar'
323
+ * };
324
+ *
325
+ * management.users.updateAppMetadata(params, metadata, function (err, user) {
326
+ * if (err) {
327
+ * // Handle error.
328
+ * }
329
+ *
330
+ * // Updated user.
331
+ * console.log(user);
332
+ * });
333
+ * @param {object} params The user data object..
334
+ * @param {string} params.id The user id.
335
+ * @param {object} metadata New app metadata.
336
+ * @param {Function} [cb] Callback function
337
+ * @returns {Promise|undefined}
338
+ */
339
+ updateAppMetadata(params, metadata, cb) {
340
+ const data = {
341
+ app_metadata: metadata,
342
+ };
352
343
 
353
- /**
354
- * Update the app metadata.
355
- *
356
- * @method updateAppMetadata
357
- * @memberOf module:management.UsersManager.prototype
358
- *
359
- * @example
360
- * var params = { id: USER_ID };
361
- * var metadata = {
362
- * foo: 'bar'
363
- * };
364
- *
365
- * management.users.updateAppMetadata(params, metadata, function (err, user) {
366
- * if (err) {
367
- * // Handle error.
368
- * }
369
- *
370
- * // Updated user.
371
- * console.log(user);
372
- * });
373
- *
374
- * @param {Object} params The user data object..
375
- * @param {String} params.id The user id.
376
- * @param {Object} metadata New app metadata.
377
- * @param {Function} [cb] Callback function
378
- *
379
- * @return {Promise|undefined}
380
- */
381
- UsersManager.prototype.updateAppMetadata = function(params, metadata, cb) {
382
- var data = {
383
- app_metadata: metadata
384
- };
344
+ if (cb && cb instanceof Function) {
345
+ return this.users.patch(params, data, cb);
346
+ }
385
347
 
386
- if (cb && cb instanceof Function) {
387
- return this.users.patch(params, data, cb);
348
+ return this.users.patch(params, data);
388
349
  }
389
350
 
390
- return this.users.patch(params, data);
391
- };
351
+ /**
352
+ * Delete a user by its id.
353
+ *
354
+ * @example
355
+ * management.users.delete({ id: USER_ID }, function (err) {
356
+ * if (err) {
357
+ * // Handle error.
358
+ * }
359
+ *
360
+ * // User deleted.
361
+ * });
362
+ * @param {object} params The user data object..
363
+ * @param {string} params.id The user id.
364
+ * @param {Function} [cb] Callback function
365
+ * @returns {Promise|undefined}
366
+ */
367
+ delete(params, ...restOfArgs) {
368
+ if (typeof params !== 'object' || typeof params.id !== 'string') {
369
+ throw new ArgumentError('You must provide an id for the delete method');
370
+ }
392
371
 
393
- /**
394
- * Delete a user by its id.
395
- *
396
- * @method delete
397
- * @memberOf module:management.UsersManager.prototype
398
- *
399
- * @example
400
- * management.users.delete({ id: USER_ID }, function (err) {
401
- * if (err) {
402
- * // Handle error.
403
- * }
404
- *
405
- * // User deleted.
406
- * });
407
- *
408
- *
409
- * @param {Object} params The user data object..
410
- * @param {String} params.id The user id.
411
- * @param {Function} [cb] Callback function
412
- *
413
- * @return {Promise|undefined}
414
- */
415
- UsersManager.prototype.delete = function(params) {
416
- if (typeof params !== 'object' || typeof params.id !== 'string') {
417
- throw new ArgumentError('You must provide an id for the delete method');
372
+ return this.users.delete(params, ...restOfArgs);
418
373
  }
419
374
 
420
- return this.users.delete.apply(this.users, arguments);
421
- };
375
+ /**
376
+ * Delete all users.
377
+ *
378
+ * @example
379
+ * management.users.deleteAll(function (err) {
380
+ * if (err) {
381
+ * // Handle error.
382
+ * }
383
+ *
384
+ * // Users deleted
385
+ * });
386
+ * @param {Function} [cb] Callback function
387
+ * @returns {Promise|undefined}
388
+ * @deprecated This method will be removed in the next major release.
389
+ */
390
+ deleteAll(cb, ...restOfArgs) {
391
+ if (typeof cb !== 'function') {
392
+ const errorMsg = 'The deleteAll method only accepts a callback as argument';
422
393
 
423
- /**
424
- * Delete all users.
425
- *
426
- * @method deleteAll
427
- * @memberOf module:management.UsersManager.prototype
428
- *
429
- * @example
430
- * management.users.deleteAll(function (err) {
431
- * if (err) {
432
- * // Handle error.
433
- * }
434
- *
435
- * // Users deleted
436
- * });
437
- *
438
- * @param {Function} [cb] Callback function
439
- *
440
- * @return {Promise|undefined}
441
- *
442
- * @deprecated This method will be removed in the next major release.
443
- */
444
- UsersManager.prototype.deleteAll = function(cb) {
445
- if (typeof cb !== 'function') {
446
- var errorMsg = 'The deleteAll method only accepts a callback as argument';
394
+ throw new ArgumentError(errorMsg);
395
+ }
447
396
 
448
- throw new ArgumentError(errorMsg);
397
+ return this.users.delete(cb, ...restOfArgs);
449
398
  }
450
399
 
451
- return this.users.delete.apply(this.users, arguments);
452
- };
400
+ /**
401
+ * Delete a multifactor provider.
402
+ *
403
+ * @example
404
+ * var params = { id: USER_ID, provider: MULTIFACTOR_PROVIDER };
405
+ *
406
+ * management.users.deleteMultifactorProvider(params, function (err, user) {
407
+ * if (err) {
408
+ * // Handle error.
409
+ * }
410
+ *
411
+ * // Users accounts unlinked.
412
+ * });
413
+ * @param {object} params Data object.
414
+ * @param {string} params.id The user id.
415
+ * @param {string} params.provider Multifactor provider.
416
+ * @param {Function} [cb] Callback function
417
+ * @returns {Promise|undefined}
418
+ */
419
+ deleteMultifactorProvider(params, cb) {
420
+ params = params || {};
453
421
 
454
- /**
455
- * Delete a multifactor provider.
456
- *
457
- * @method deleteMultifactorProvider
458
- * @memberOf module:management.UsersManager.prototype
459
- *
460
- * @example
461
- * var params = { id: USER_ID, provider: MULTIFACTOR_PROVIDER };
462
- *
463
- * management.users.deleteMultifactorProvider(params, function (err, user) {
464
- * if (err) {
465
- * // Handle error.
466
- * }
467
- *
468
- * // Users accounts unlinked.
469
- * });
470
- *
471
- * @param {Object} params Data object.
472
- * @param {String} params.id The user id.
473
- * @param {String} params.provider Multifactor provider.
474
- * @param {Function} [cb] Callback function
475
- *
476
- * @return {Promise|undefined}
477
- */
478
- UsersManager.prototype.deleteMultifactorProvider = function(params, cb) {
479
- params = params || {};
422
+ if (!params.id || typeof params.id !== 'string') {
423
+ throw new ArgumentError('The id parameter must be a valid user id');
424
+ }
480
425
 
481
- if (!params.id || typeof params.id !== 'string') {
482
- throw new ArgumentError('The id parameter must be a valid user id');
483
- }
426
+ if (!params.provider || typeof params.provider !== 'string') {
427
+ throw new ArgumentError('Must specify a provider');
428
+ }
484
429
 
485
- if (!params.provider || typeof params.provider !== 'string') {
486
- throw new ArgumentError('Must specify a provider');
487
- }
430
+ if (cb && cb instanceof Function) {
431
+ return this.multifactor.delete(params, cb);
432
+ }
488
433
 
489
- if (cb && cb instanceof Function) {
490
- return this.multifactor.delete(params, cb);
434
+ return this.multifactor.delete(params);
491
435
  }
492
436
 
493
- return this.multifactor.delete(params);
494
- };
437
+ /**
438
+ * Link the user with another account.
439
+ *
440
+ * @example
441
+ * var userId = 'USER_ID';
442
+ * var params = {
443
+ * user_id: 'OTHER_USER_ID',
444
+ * connection_id: 'CONNECTION_ID'
445
+ * };
446
+ *
447
+ * management.users.link(userId, params, function (err, user) {
448
+ * if (err) {
449
+ * // Handle error.
450
+ * }
451
+ *
452
+ * // Users linked.
453
+ * });
454
+ * @param {string} userId ID of the primary user.
455
+ * @param {object} params Secondary user data.
456
+ * @param {string} params.user_id ID of the user to be linked.
457
+ * @param {string} params.connection_id ID of the connection to be used.
458
+ * @param {string} params.provider Identity provider of the secondary user account being linked.
459
+ * @param {string} params.link_with JWT for the secondary account being linked. If sending this parameter, provider, user_id, and connection_id must not be sent.
460
+ * @param {Function} [cb] Callback function.
461
+ * @returns {Promise|undefined}
462
+ */
463
+ link(userId, params, cb) {
464
+ const query = { id: userId };
465
+ params = params || {};
495
466
 
496
- /**
497
- * Link the user with another account.
498
- *
499
- * @method link
500
- * @memberOf module:management.UsersManager.prototype
501
- *
502
- * @example
503
- * var userId = 'USER_ID';
504
- * var params = {
505
- * user_id: 'OTHER_USER_ID',
506
- * connection_id: 'CONNECTION_ID'
507
- * };
508
- *
509
- * management.users.link(userId, params, function (err, user) {
510
- * if (err) {
511
- * // Handle error.
512
- * }
513
- *
514
- * // Users linked.
515
- * });
516
- *
517
- * @param {String} userId ID of the primary user.
518
- * @param {Object} params Secondary user data.
519
- * @param {String} params.user_id ID of the user to be linked.
520
- * @param {String} params.connection_id ID of the connection to be used.
521
- * @param {String} params.provider Identity provider of the secondary user account being linked.
522
- * @param {String} params.link_with JWT for the secondary account being linked. If sending this parameter, provider, user_id, and connection_id must not be sent.
523
- * @param {Function} [cb] Callback function.
524
- *
525
- * @return {Promise|undefined}
526
- */
527
- UsersManager.prototype.link = function(userId, params, cb) {
528
- var query = { id: userId };
529
- params = params || {};
467
+ // Require a user ID.
468
+ if (!userId) {
469
+ throw new ArgumentError('The userId cannot be null or undefined');
470
+ }
471
+ if (typeof userId !== 'string') {
472
+ throw new ArgumentError('The userId has to be a string');
473
+ }
530
474
 
531
- // Require a user ID.
532
- if (!userId) {
533
- throw new ArgumentError('The userId cannot be null or undefined');
534
- }
535
- if (typeof userId !== 'string') {
536
- throw new ArgumentError('The userId has to be a string');
537
- }
475
+ if (cb && cb instanceof Function) {
476
+ return this.identities.create(query, params, cb);
477
+ }
538
478
 
539
- if (cb && cb instanceof Function) {
540
- return this.identities.create(query, params, cb);
479
+ return this.identities.create(query, params);
541
480
  }
542
481
 
543
- return this.identities.create(query, params);
544
- };
482
+ /**
483
+ * Unlink the given accounts.
484
+ *
485
+ * @example
486
+ * var params = { id: USER_ID, provider: 'auht0', user_id: OTHER_USER_ID };
487
+ *
488
+ * management.users.unlink(params, function (err, user) {
489
+ * if (err) {
490
+ * // Handle error.
491
+ * }
492
+ *
493
+ * // Users accounts unlinked.
494
+ * });
495
+ * @param {object} params Linked users data.
496
+ * @param {string} params.id Primary user ID.
497
+ * @param {string} params.provider Identity provider in use.
498
+ * @param {string} params.user_id Secondary user ID.
499
+ * @param {Function} [cb] Callback function.
500
+ * @returns {Promise|undefined}
501
+ */
502
+ unlink(params, cb) {
503
+ params = params || {};
545
504
 
546
- /**
547
- * Unlink the given accounts.
548
- *
549
- * @method unlink
550
- * @memberOf module:management.UsersManager.prototype
551
- *
552
- * @example
553
- * var params = { id: USER_ID, provider: 'auht0', user_id: OTHER_USER_ID };
554
- *
555
- * management.users.unlink(params, function (err, user) {
556
- * if (err) {
557
- * // Handle error.
558
- * }
559
- *
560
- * // Users accounts unlinked.
561
- * });
562
- *
563
- * @param {Object} params Linked users data.
564
- * @param {String} params.id Primary user ID.
565
- * @param {String} params.provider Identity provider in use.
566
- * @param {String} params.user_id Secondary user ID.
567
- * @param {Function} [cb] Callback function.
568
- *
569
- * @return {Promise|undefined}
570
- */
571
- UsersManager.prototype.unlink = function(params, cb) {
572
- params = params || {};
505
+ if (!params.id || typeof params.id !== 'string') {
506
+ throw new ArgumentError('id field is required');
507
+ }
573
508
 
574
- if (!params.id || typeof params.id !== 'string') {
575
- throw new ArgumentError('id field is required');
576
- }
509
+ if (!params.user_id || typeof params.user_id !== 'string') {
510
+ throw new ArgumentError('user_id field is required');
511
+ }
577
512
 
578
- if (!params.user_id || typeof params.user_id !== 'string') {
579
- throw new ArgumentError('user_id field is required');
580
- }
513
+ if (!params.provider || typeof params.provider !== 'string') {
514
+ throw new ArgumentError('provider field is required');
515
+ }
581
516
 
582
- if (!params.provider || typeof params.provider !== 'string') {
583
- throw new ArgumentError('provider field is required');
584
- }
517
+ if (cb && cb instanceof Function) {
518
+ return this.identities.delete(params, cb);
519
+ }
585
520
 
586
- if (cb && cb instanceof Function) {
587
- return this.identities.delete(params, cb);
521
+ return this.identities.delete(params);
588
522
  }
589
523
 
590
- return this.identities.delete(params);
591
- };
524
+ /**
525
+ * Get user's log events.
526
+ *
527
+ * @example
528
+ * var params = { id: USER_ID, page: 0, per_page: 50, sort: 'date:-1', include_totals: true };
529
+ *
530
+ * management.users.logs(params, function (err, logs) {
531
+ * if (err) {
532
+ * // Handle error.
533
+ * }
534
+ *
535
+ * console.log(logs);
536
+ * });
537
+ * @param {object} params Get logs data.
538
+ * @param {string} params.id User id.
539
+ * @param {number} params.per_page Number of results per page.
540
+ * @param {number} params.page Page number, zero indexed.
541
+ * @param {string} params.sort The field to use for sorting. Use field:order where order is 1 for ascending and -1 for descending. For example date:-1.
542
+ * @param {boolean} params.include_totals true if a query summary must be included in the result, false otherwise. Default false;
543
+ * @param {Function} [cb] Callback function.
544
+ * @returns {Promise|undefined}
545
+ */
546
+ logs(params, cb) {
547
+ params = params || {};
592
548
 
593
- /**
594
- * Get user's log events.
595
- *
596
- * @method logs
597
- * @memberOf module:management.UsersManager.prototype
598
- *
599
- * @example
600
- * var params = { id: USER_ID, page: 0, per_page: 50, sort: 'date:-1', include_totals: true };
601
- *
602
- * management.users.logs(params, function (err, logs) {
603
- * if (err) {
604
- * // Handle error.
605
- * }
606
- *
607
- * console.log(logs);
608
- * });
609
- *
610
- * @param {Object} params Get logs data.
611
- * @param {String} params.id User id.
612
- * @param {Number} params.per_page Number of results per page.
613
- * @param {Number} params.page Page number, zero indexed.
614
- * @param {String} params.sort The field to use for sorting. Use field:order where order is 1 for ascending and -1 for descending. For example date:-1.
615
- * @param {Boolean} params.include_totals true if a query summary must be included in the result, false otherwise. Default false;
616
- * @param {Function} [cb] Callback function.
617
- *
618
- * @return {Promise|undefined}
619
- */
620
- UsersManager.prototype.logs = function(params, cb) {
621
- params = params || {};
549
+ if (!params.id || typeof params.id !== 'string') {
550
+ throw new ArgumentError('id field is required');
551
+ }
552
+
553
+ return this.userLogs.get(params, cb);
554
+ }
622
555
 
623
- if (!params.id || typeof params.id !== 'string') {
624
- throw new ArgumentError('id field is required');
556
+ /**
557
+ * Get a list of Guardian enrollments.
558
+ *
559
+ * @example
560
+ * management.users.getGuardianEnrollments({ id: USER_ID }, function (err, enrollments) {
561
+ * console.log(enrollments);
562
+ * });
563
+ * @param {object} data The user data object.
564
+ * @param {string} data.id The user id.
565
+ * @param {Function} [cb] Callback function.
566
+ * @returns {Promise|undefined}
567
+ */
568
+ getGuardianEnrollments(...args) {
569
+ return this.enrollments.get(...args);
625
570
  }
626
571
 
627
- return this.userLogs.get(params, cb);
628
- };
572
+ /**
573
+ * Generate new Guardian recovery code.
574
+ *
575
+ * @example
576
+ * management.users.regenerateRecoveryCode("USER_ID", function (err, result) {
577
+ * console.log(result.recovery_code);
578
+ * });
579
+ * @param {object} params Get logs data.
580
+ * @param {string} params.id User id.
581
+ * @param {Function} [cb] Callback function.
582
+ * @returns {Promise|undefined}
583
+ */
584
+ regenerateRecoveryCode(params, cb) {
585
+ if (!params || !params.id) {
586
+ throw new ArgumentError('The userId cannot be null or undefined');
587
+ }
629
588
 
630
- /**
631
- * Get a list of Guardian enrollments.
632
- *
633
- * @method getGuardianEnrollments
634
- * @memberOf module:management.UsersManager.prototype
635
- *
636
- * @example
637
- * management.users.getGuardianEnrollments({ id: USER_ID }, function (err, enrollments) {
638
- * console.log(enrollments);
639
- * });
640
- *
641
- * @param {Object} data The user data object.
642
- * @param {String} data.id The user id.
643
- * @param {Function} [cb] Callback function.
644
- *
645
- * @return {Promise|undefined}
646
- */
647
- UsersManager.prototype.getGuardianEnrollments = function() {
648
- return this.enrollments.get.apply(this.enrollments, arguments);
649
- };
589
+ if (cb && cb instanceof Function) {
590
+ return this.recoveryCodeRegenerations.create(params, {}, cb);
591
+ }
650
592
 
651
- /**
652
- * Generate new Guardian recovery code.
653
- *
654
- * @method regenerateRecoveryCode
655
- * @memberOf module:management.UsersManager.prototype
656
- *
657
- * @example
658
- * management.users.regenerateRecoveryCode("USER_ID", function (err, result) {
659
- * console.log(result.recovery_code);
660
- * });
661
- *
662
- * @param {Object} params Get logs data.
663
- * @param {String} params.id User id.
664
- * @param {Function} [cb] Callback function.
665
- *
666
- * @return {Promise|undefined}
667
- */
668
- UsersManager.prototype.regenerateRecoveryCode = function(params, cb) {
669
- if (!params || !params.id) {
670
- throw new ArgumentError('The userId cannot be null or undefined');
593
+ return this.recoveryCodeRegenerations.create(params, {});
671
594
  }
672
595
 
673
- if (cb && cb instanceof Function) {
674
- return this.recoveryCodeRegenerations.create(params, {}, cb);
675
- }
596
+ /**
597
+ * Invalidate all remembered browsers for MFA.
598
+ *
599
+ * @example
600
+ * management.users.invalidateRememberBrowser({ id: USER_ID }, function (err, result) {
601
+ * if (err) {
602
+ * // Handle error.
603
+ * }
604
+ *
605
+ * // Invalidated all remembered browsers.
606
+ * });
607
+ * @param {object} params The user data object.
608
+ * @param {string} params.id The user id.
609
+ * @param {Function} [cb] Callback function.
610
+ * @returns {Promise|undefined}
611
+ */
612
+ invalidateRememberBrowser(params, cb) {
613
+ if (!params || !params.id) {
614
+ throw new ArgumentError('The userId cannot be null or undefined');
615
+ }
676
616
 
677
- return this.recoveryCodeRegenerations.create(params, {});
678
- };
617
+ if (cb && cb instanceof Function) {
618
+ return this.invalidateRememberBrowsers.create(params, {}, cb);
619
+ }
679
620
 
680
- /**
681
- * Invalidate all remembered browsers for MFA.
682
- *
683
- * @method invalidateRememberBrowser
684
- * @memberOf module:management.UsersManager.prototype
685
- *
686
- * @example
687
- * management.users.invalidateRememberBrowser({ id: USER_ID }, function (err, result) {
688
- * if (err) {
689
- * // Handle error.
690
- * }
691
- *
692
- * // Invalidated all remembered browsers.
693
- * });
694
- *
695
- * @param {Object} params The user data object.
696
- * @param {String} params.id The user id.
697
- * @param {Function} [cb] Callback function.
698
- *
699
- * @return {Promise|undefined}
700
- */
701
- UsersManager.prototype.invalidateRememberBrowser = function(params, cb) {
702
- if (!params || !params.id) {
703
- throw new ArgumentError('The userId cannot be null or undefined');
621
+ return this.invalidateRememberBrowsers.create(params, {});
704
622
  }
705
623
 
706
- if (cb && cb instanceof Function) {
707
- return this.invalidateRememberBrowsers.create(params, {}, cb);
624
+ /**
625
+ * Get a list of roles for a user.
626
+ *
627
+ * @example
628
+ * management.users.getRoles({ id: USER_ID }, function (err, roles) {
629
+ * console.log(roles);
630
+ * });
631
+ * @param {object} data The user data object.
632
+ * @param {string} data.id The user id.
633
+ * @param {Function} [cb] Callback function.
634
+ * @returns {Promise|undefined}
635
+ */
636
+ getRoles(...args) {
637
+ return this.roles.getAll(...args);
708
638
  }
709
639
 
710
- return this.invalidateRememberBrowsers.create(params, {});
711
- };
640
+ /**
641
+ * Assign roles to a user
642
+ *
643
+ * @example
644
+ * var params = { id : 'USER_ID';
645
+ * var data = { "roles" : ["roleId1", "roleID2"]};
646
+ *
647
+ * management.users.assignRoles(params, data, function (err, user) {
648
+ * if (err) {
649
+ * // Handle error.
650
+ * }
651
+ *
652
+ * // roles added.
653
+ * });
654
+ * @param {object} params params object
655
+ * @param {string} params.id user_id
656
+ * @param {string} data data object containing list of role IDs
657
+ * @param {string} data.roles Array of role IDs
658
+ * @param {Function} [cb] Callback function.
659
+ * @returns {Promise|undefined}
660
+ */
712
661
 
713
- /**
714
- * Get a list of roles for a user.
715
- *
716
- * @method getUserRoles
717
- * @memberOf module:management.UsersManager.prototype
718
- *
719
- * @example
720
- * management.users.getRoles({ id: USER_ID }, function (err, roles) {
721
- * console.log(roles);
722
- * });
723
- *
724
- * @param {Object} data The user data object.
725
- * @param {String} data.id The user id.
726
- * @param {Function} [cb] Callback function.
727
- *
728
- * @return {Promise|undefined}
729
- */
730
- UsersManager.prototype.getRoles = function() {
731
- return this.roles.getAll.apply(this.roles, arguments);
732
- };
662
+ assignRoles(params, data, cb) {
663
+ const query = params || {};
664
+ data = data || {};
733
665
 
734
- /**
735
- * Assign roles to a user
736
- *
737
- * @method assignRoles
738
- * @memberOf module:management.RolesManager.prototype
739
- *
740
- * @example
741
- * var params = { id : 'USER_ID';
742
- * var data = { "roles" : ["roleId1", "roleID2"]};
743
- *
744
- * management.users.assignRoles(params, data, function (err, user) {
745
- * if (err) {
746
- * // Handle error.
747
- * }
748
- *
749
- * // roles added.
750
- * });
751
- *
752
- * @param {Object} params params object
753
- * @param {String} params.id user_id
754
- * @param {String} data data object containing list of role IDs
755
- * @param {String} data.roles Array of role IDs
756
- * @param {Function} [cb] Callback function.
757
- *
758
- * @return {Promise|undefined}
759
- */
666
+ // Require a user ID.
667
+ if (!params.id) {
668
+ throw new ArgumentError('The user_id cannot be null or undefined');
669
+ }
670
+ if (typeof params.id !== 'string') {
671
+ throw new ArgumentError('The user_id has to be a string');
672
+ }
760
673
 
761
- UsersManager.prototype.assignRoles = function(params, data, cb) {
762
- var query = params || {};
763
- data = data || {};
674
+ if (cb && cb instanceof Function) {
675
+ return this.roles.create(query, data, cb);
676
+ }
764
677
 
765
- // Require a user ID.
766
- if (!params.id) {
767
- throw new ArgumentError('The user_id cannot be null or undefined');
768
- }
769
- if (typeof params.id !== 'string') {
770
- throw new ArgumentError('The user_id has to be a string');
678
+ return this.roles.create(query, data);
771
679
  }
772
680
 
773
- if (cb && cb instanceof Function) {
774
- return this.roles.create(query, data, cb);
775
- }
681
+ /**
682
+ * Remove roles from a user
683
+ *
684
+ * @example
685
+ * var params = { id : 'USER_ID';
686
+ * var data = { "roles" : ["roleId1", "roleID2"]};
687
+ *
688
+ * management.users.removeRoles(params, data, function (err, user) {
689
+ * if (err) {
690
+ * // Handle error.
691
+ * }
692
+ *
693
+ * // roles removed.
694
+ * });
695
+ * @param {object} params params object
696
+ * @param {string} params.id user_id
697
+ * @param {string} data data object containing list of role IDs
698
+ * @param {string} data.roles Array of role IDs
699
+ * @param {Function} [cb] Callback function.
700
+ * @returns {Promise|undefined}
701
+ */
776
702
 
777
- return this.roles.create(query, data);
778
- };
703
+ removeRoles(params, data, cb) {
704
+ const query = params || {};
705
+ data = data || {};
779
706
 
780
- /**
781
- * Remove roles from a user
782
- *
783
- * @method removeRoles
784
- * @memberOf module:management.RolesManager.prototype
785
- *
786
- * @example
787
- * var params = { id : 'USER_ID';
788
- * var data = { "roles" : ["roleId1", "roleID2"]};
789
- *
790
- * management.users.removeRoles(params, data, function (err, user) {
791
- * if (err) {
792
- * // Handle error.
793
- * }
794
- *
795
- * // roles removed.
796
- * });
797
- *
798
- * @param {Object} params params object
799
- * @param {String} params.id user_id
800
- * @param {String} data data object containing list of role IDs
801
- * @param {String} data.roles Array of role IDs
802
- * @param {Function} [cb] Callback function.
803
- *
804
- * @return {Promise|undefined}
805
- */
707
+ // Require a user ID.
708
+ if (!params.id) {
709
+ throw new ArgumentError('The user_id cannot be null or undefined');
710
+ }
711
+ if (typeof params.id !== 'string') {
712
+ throw new ArgumentError('The user_id has to be a string');
713
+ }
806
714
 
807
- UsersManager.prototype.removeRoles = function(params, data, cb) {
808
- var query = params || {};
809
- data = data || {};
715
+ if (cb && cb instanceof Function) {
716
+ return this.roles.delete(query, data, cb);
717
+ }
810
718
 
811
- // Require a user ID.
812
- if (!params.id) {
813
- throw new ArgumentError('The user_id cannot be null or undefined');
814
- }
815
- if (typeof params.id !== 'string') {
816
- throw new ArgumentError('The user_id has to be a string');
719
+ return this.roles.delete(query, data);
817
720
  }
818
721
 
819
- if (cb && cb instanceof Function) {
820
- return this.roles.delete(query, data, cb);
722
+ /**
723
+ * Get a list of permissions for a user.
724
+ *
725
+ * @example
726
+ * management.users.getPermissions({ id: USER_ID }, function (err, permissions) {
727
+ * console.log(permissions);
728
+ * });
729
+ * @param {object} data The user data object.
730
+ * @param {string} data.id The user id.
731
+ * @param {Function} [cb] Callback function.
732
+ * @returns {Promise|undefined}
733
+ */
734
+ getPermissions(...args) {
735
+ return this.permissions.getAll(...args);
821
736
  }
822
737
 
823
- return this.roles.delete(query, data);
824
- };
738
+ /**
739
+ * Assign permissions to a user
740
+ *
741
+ * @example
742
+ * var params = { id : 'USER_ID';
743
+ * var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};
744
+ *
745
+ * management.users.assignPermissions(params, data, function (err, user) {
746
+ * if (err) {
747
+ * // Handle error.
748
+ * }
749
+ *
750
+ * // permissions added.
751
+ * });
752
+ * @param {object} params params object
753
+ * @param {string} params.id user_id
754
+ * @param {string} data data object containing list of permissions
755
+ * @param {string} data.permissions Array of permission IDs
756
+ * @param {Function} [cb] Callback function.
757
+ * @returns {Promise|undefined}
758
+ */
825
759
 
826
- /**
827
- * Get a list of permissions for a user.
828
- *
829
- * @method getPermissions
830
- * @memberOf module:management.UsersManager.prototype
831
- *
832
- * @example
833
- * management.users.getPermissions({ id: USER_ID }, function (err, permissions) {
834
- * console.log(permissions);
835
- * });
836
- *
837
- * @param {Object} data The user data object.
838
- * @param {String} data.id The user id.
839
- * @param {Function} [cb] Callback function.
840
- *
841
- * @return {Promise|undefined}
842
- */
843
- UsersManager.prototype.getPermissions = function() {
844
- return this.permissions.getAll.apply(this.permissions, arguments);
845
- };
760
+ assignPermissions(params, data, cb) {
761
+ const query = params || {};
762
+ data = data || {};
846
763
 
847
- /**
848
- * Assign permissions to a user
849
- *
850
- * @method assignPermissions
851
- * @memberOf module:management.permissionsManager.prototype
852
- *
853
- * @example
854
- * var params = { id : 'USER_ID';
855
- * var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};
856
- *
857
- * management.users.assignPermissions(params, data, function (err, user) {
858
- * if (err) {
859
- * // Handle error.
860
- * }
861
- *
862
- * // permissions added.
863
- * });
864
- *
865
- * @param {Object} params params object
866
- * @param {String} params.id user_id
867
- * @param {String} data data object containing list of permissions
868
- * @param {String} data.permissions Array of permission IDs
869
- * @param {Function} [cb] Callback function.
870
- *
871
- * @return {Promise|undefined}
872
- */
764
+ // Require a user ID.
765
+ if (!params.id) {
766
+ throw new ArgumentError('The user_id cannot be null or undefined');
767
+ }
768
+ if (typeof params.id !== 'string') {
769
+ throw new ArgumentError('The user_id has to be a string');
770
+ }
873
771
 
874
- UsersManager.prototype.assignPermissions = function(params, data, cb) {
875
- var query = params || {};
876
- data = data || {};
772
+ if (cb && cb instanceof Function) {
773
+ return this.permissions.create(query, data, cb);
774
+ }
877
775
 
878
- // Require a user ID.
879
- if (!params.id) {
880
- throw new ArgumentError('The user_id cannot be null or undefined');
881
- }
882
- if (typeof params.id !== 'string') {
883
- throw new ArgumentError('The user_id has to be a string');
776
+ return this.permissions.create(query, data);
884
777
  }
885
778
 
886
- if (cb && cb instanceof Function) {
887
- return this.permissions.create(query, data, cb);
888
- }
779
+ /**
780
+ * Remove permissions from a user
781
+ *
782
+ * @example
783
+ * var params = { id : 'USER_ID';
784
+ * var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};
785
+ *
786
+ * management.users.removePermissions(params, data, function (err, user) {
787
+ * if (err) {
788
+ * // Handle error.
789
+ * }
790
+ *
791
+ * // permissions removed.
792
+ * });
793
+ * @param {object} params params object
794
+ * @param {string} params.id user_id
795
+ * @param {object} data data object containing list of permission IDs
796
+ * @param {string} data.permissions Array of permission IDs
797
+ * @param {Function} [cb] Callback function.
798
+ * @returns {Promise|undefined}
799
+ */
889
800
 
890
- return this.permissions.create(query, data);
891
- };
801
+ removePermissions(params, data, cb) {
802
+ const query = params || {};
803
+ data = data || {};
892
804
 
893
- /**
894
- * Remove permissions from a user
895
- *
896
- * @method removePermissions
897
- * @memberOf module:management.permissionsManager.prototype
898
- *
899
- * @example
900
- * var params = { id : 'USER_ID';
901
- * var data = { "permissions" : [{"permission_name" :"do:something" ,"resource_server_identifier" :"test123" }]};
902
- *
903
- * management.users.removePermissions(params, data, function (err, user) {
904
- * if (err) {
905
- * // Handle error.
906
- * }
907
- *
908
- * // permissions removed.
909
- * });
910
- *
911
- * @param {Object} params params object
912
- * @param {String} params.id user_id
913
- * @param {String} data data object containing list of permission IDs
914
- * @param {String} data.permissions Array of permission IDs
915
- * @param {Function} [cb] Callback function.
916
- *
917
- * @return {Promise|undefined}
918
- */
805
+ // Require a user ID.
806
+ if (!params.id) {
807
+ throw new ArgumentError('The user_id cannot be null or undefined');
808
+ }
809
+ if (typeof params.id !== 'string') {
810
+ throw new ArgumentError('The user_id has to be a string');
811
+ }
919
812
 
920
- UsersManager.prototype.removePermissions = function(params, data, cb) {
921
- var query = params || {};
922
- data = data || {};
813
+ if (cb && cb instanceof Function) {
814
+ return this.permissions.delete(query, data, cb);
815
+ }
923
816
 
924
- // Require a user ID.
925
- if (!params.id) {
926
- throw new ArgumentError('The user_id cannot be null or undefined');
927
- }
928
- if (typeof params.id !== 'string') {
929
- throw new ArgumentError('The user_id has to be a string');
817
+ return this.permissions.delete(query, data);
930
818
  }
931
819
 
932
- if (cb && cb instanceof Function) {
933
- return this.permissions.delete(query, data, cb);
820
+ /**
821
+ * Get a list of organizations for a user.
822
+ *
823
+ * @example
824
+ * management.users.getUserOrganizations({ id: USER_ID }, function (err, orgs) {
825
+ * console.log(orgs);
826
+ * });
827
+ * @param {object} data The user data object.
828
+ * @param {string} data.id The user id.
829
+ * @param {Function} [cb] Callback function.
830
+ * @returns {Promise|undefined}
831
+ */
832
+ getUserOrganizations(...args) {
833
+ return this.organizations.getAll(...args);
934
834
  }
935
-
936
- return this.permissions.delete(query, data);
937
- };
938
-
939
- /**
940
- * Get a list of organizations for a user.
941
- *
942
- * @method getUserOrganizations
943
- * @memberOf module:management.UsersManager.prototype
944
- *
945
- * @example
946
- * management.users.getUserOrganizations({ id: USER_ID }, function (err, orgs) {
947
- * console.log(orgs);
948
- * });
949
- *
950
- * @param {Object} data The user data object.
951
- * @param {String} data.id The user id.
952
- * @param {Function} [cb] Callback function.
953
- *
954
- * @return {Promise|undefined}
955
- */
956
- UsersManager.prototype.getUserOrganizations = function() {
957
- return this.organizations.getAll.apply(this.organizations, arguments);
958
- };
835
+ }
959
836
 
960
837
  module.exports = UsersManager;