auth0 2.36.1 → 2.38.1

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 +557 -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 +238 -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 -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 -3619
  46. package/src/utils.js +31 -60
@@ -1,389 +1,356 @@
1
- var axios = require('axios');
2
- var extend = require('util')._extend;
3
- var FormData = require('form-data');
4
- var fs = require('fs');
1
+ const axios = require('axios');
2
+ const FormData = require('form-data');
3
+ const fs = require('fs');
5
4
 
6
- var ArgumentError = require('rest-facade').ArgumentError;
7
- var Auth0RestClient = require('../Auth0RestClient');
8
- var RetryRestClient = require('../RetryRestClient');
5
+ const { ArgumentError } = require('rest-facade');
6
+ const Auth0RestClient = require('../Auth0RestClient');
7
+ const RetryRestClient = require('../RetryRestClient');
9
8
 
10
9
  /**
11
- * Simple facade for consuming a REST API endpoint.
12
- * @external RestClient
13
- * @see https://github.com/ngonzalvez/rest-facade
14
- */
15
-
16
- /**
17
- * @class
18
10
  * Abstract the creation as well as the retrieval of async jobs.
19
- * @constructor
20
- * @memberOf module:management
21
- *
22
- * @param {Object} options The client options.
23
- * @param {String} options.baseUrl The URL of the API.
24
- * @param {Object} [options.headers] Headers to be included in all requests.
25
- * @param {Object} [options.retry] Retry Policy Config
26
11
  */
27
- var JobsManager = function(options) {
28
- if (options === null || typeof options !== 'object') {
29
- throw new ArgumentError('Must provide client options');
30
- }
31
-
32
- if (options.baseUrl === null || options.baseUrl === undefined) {
33
- throw new ArgumentError('Must provide a base URL for the API');
34
- }
35
-
36
- if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
37
- throw new ArgumentError('The provided base URL is invalid');
38
- }
39
-
40
- var clientOptions = {
41
- errorFormatter: { message: 'message', name: 'error' },
42
- headers: options.headers,
43
- query: { repeatParams: false }
44
- };
45
-
46
- this.options = options;
47
-
12
+ class JobsManager {
48
13
  /**
49
- * Provides an abstraction layer for consuming the
50
- * {@link https://auth0.com/docs/api/v2#!/Jobs Jobs endpoint}.
51
- *
52
- * @type {external:RestClient}
14
+ * @param {object} options The client options.
15
+ * @param {string} options.baseUrl The URL of the API.
16
+ * @param {object} [options.headers] Headers to be included in all requests.
17
+ * @param {object} [options.retry] Retry Policy Config
53
18
  */
54
- var auth0RestClient = new Auth0RestClient(
55
- options.baseUrl + '/jobs/:id',
56
- clientOptions,
57
- options.tokenProvider
58
- );
59
- this.jobs = new RetryRestClient(auth0RestClient, options.retry);
19
+ constructor(options) {
20
+ if (options === null || typeof options !== 'object') {
21
+ throw new ArgumentError('Must provide client options');
22
+ }
23
+
24
+ if (options.baseUrl === null || options.baseUrl === undefined) {
25
+ throw new ArgumentError('Must provide a base URL for the API');
26
+ }
27
+
28
+ if ('string' !== typeof options.baseUrl || options.baseUrl.length === 0) {
29
+ throw new ArgumentError('The provided base URL is invalid');
30
+ }
31
+
32
+ const clientOptions = {
33
+ errorFormatter: { message: 'message', name: 'error' },
34
+ headers: options.headers,
35
+ query: { repeatParams: false },
36
+ };
37
+
38
+ this.options = options;
39
+
40
+ /**
41
+ * Provides an abstraction layer for consuming the
42
+ * {@link https://auth0.com/docs/api/v2#!/Jobs Jobs endpoint}.
43
+ *
44
+ * @type {external:RestClient}
45
+ */
46
+ const auth0RestClient = new Auth0RestClient(
47
+ `${options.baseUrl}/jobs/:id`,
48
+ clientOptions,
49
+ options.tokenProvider
50
+ );
51
+ this.jobs = new RetryRestClient(auth0RestClient, options.retry);
52
+
53
+ /**
54
+ * Provides an abstraction layer for consuming the
55
+ * {@link https://auth0.com/docs/api/v2#!/Jobs/:id/errors Errors endpoint}.
56
+ *
57
+ * @type {external:RestClient}
58
+ */
59
+ const jobErrorsRestClient = new Auth0RestClient(
60
+ `${options.baseUrl}/jobs/:id/errors`,
61
+ clientOptions,
62
+ options.tokenProvider
63
+ );
64
+ this.jobErrors = new RetryRestClient(jobErrorsRestClient, options.retry);
65
+
66
+ /**
67
+ * Provides an abstraction layer for consuming the
68
+ * {@link https://auth0.com/docs/api/v2#!/Jobs/post_users_exports Create job to export users endpoint}
69
+ *
70
+ * @type {external:RestClient}
71
+ */
72
+ const usersExportsRestClient = new Auth0RestClient(
73
+ `${options.baseUrl}/jobs/users-exports`,
74
+ clientOptions,
75
+ options.tokenProvider
76
+ );
77
+ this.usersExports = new RetryRestClient(usersExportsRestClient, options.retry);
78
+ }
60
79
 
61
80
  /**
62
- * Provides an abstraction layer for consuming the
63
- * {@link https://auth0.com/docs/api/v2#!/Jobs/:id/errors Errors endpoint}.
81
+ * Get a job by its ID.
64
82
  *
65
- * @type {external:RestClient}
66
- */
67
- var jobErrorsRestClient = new Auth0RestClient(
68
- options.baseUrl + '/jobs/:id/errors',
69
- clientOptions,
70
- options.tokenProvider
71
- );
72
- this.jobErrors = new RetryRestClient(jobErrorsRestClient, options.retry);
73
-
74
- /**
75
- * Provides an abstraction layer for consuming the
76
- * {@link https://auth0.com/docs/api/v2#!/Jobs/post_users_exports Create job to export users endpoint}
83
+ * @example
84
+ * var params = {
85
+ * id: '{JOB_ID}'
86
+ * };
87
+ *
88
+ * management.jobs.get(params, function (err, job) {
89
+ * if (err) {
90
+ * // Handle error.
91
+ * }
77
92
  *
78
- * @type {external:RestClient}
93
+ * // Retrieved job.
94
+ * console.log(job);
95
+ * });
96
+ * @param {object} params Job parameters.
97
+ * @param {string} params.id Job ID.
98
+ * @param {Function} [cb] Callback function.
99
+ * @returns {Promise|undefined}
79
100
  */
80
- const usersExportsRestClient = new Auth0RestClient(
81
- options.baseUrl + '/jobs/users-exports',
82
- clientOptions,
83
- options.tokenProvider
84
- );
85
- this.usersExports = new RetryRestClient(usersExportsRestClient, options.retry);
86
- };
101
+ get(params, cb) {
102
+ if (!params.id || typeof params.id !== 'string') {
103
+ throw new ArgumentError('The id parameter must be a valid job id');
104
+ }
87
105
 
88
- /**
89
- * Get a job by its ID.
90
- *
91
- * @method get
92
- * @memberOf module:management.JobsManager.prototype
93
- *
94
- * @example
95
- * var params = {
96
- * id: '{JOB_ID}'
97
- * };
98
- *
99
- * management.jobs.get(params, function (err, job) {
100
- * if (err) {
101
- * // Handle error.
102
- * }
103
- *
104
- * // Retrieved job.
105
- * console.log(job);
106
- * });
107
- *
108
- * @param {Object} params Job parameters.
109
- * @param {String} params.id Job ID.
110
- * @param {Function} [cb] Callback function.
111
- *
112
- * @return {Promise|undefined}
113
- */
114
- JobsManager.prototype.get = function(params, cb) {
115
- if (!params.id || typeof params.id !== 'string') {
116
- throw new ArgumentError('The id parameter must be a valid job id');
117
- }
106
+ if (cb && cb instanceof Function) {
107
+ return this.jobs.get(params, cb);
108
+ }
118
109
 
119
- if (cb && cb instanceof Function) {
120
- return this.jobs.get(params, cb);
110
+ // Return a promise.
111
+ return this.jobs.get(params);
121
112
  }
122
113
 
123
- // Return a promise.
124
- return this.jobs.get(params);
125
- };
126
-
127
- JobsManager.prototype._importUsers = function(data, cb) {
128
- var options = this.options;
129
- var url = options.baseUrl + '/jobs/users-imports';
130
- var userData = data.users_json ? Buffer.from(data.users_json) : fs.createReadStream(data.users);
131
- var userFilename = data.users_json ? 'users.json' : data.users;
132
-
133
- var form = new FormData();
134
- form.append('users', userData, userFilename);
135
- form.append('connection_id', data.connection_id);
136
- form.append('upsert', data.upsert === true ? 'true' : 'false');
137
- form.append('send_completion_email', data.send_completion_email === false ? 'false' : 'true');
138
-
139
- var headers = { ...options.headers, ...form.getHeaders() };
140
- headers['Content-Type'] = 'multipart/form-data';
141
-
142
- var promise = options.tokenProvider.getAccessToken().then(function(access_token) {
143
- return axios
144
- .post(url, form, { headers: { ...headers, Authorization: `Bearer ${access_token}` } })
145
- .catch(function(err) {
114
+ _importUsers(data, cb) {
115
+ const { options } = this;
116
+ const url = `${options.baseUrl}/jobs/users-imports`;
117
+ const userData = data.users_json
118
+ ? Buffer.from(data.users_json)
119
+ : fs.createReadStream(data.users);
120
+ const userFilename = data.users_json ? 'users.json' : data.users;
121
+
122
+ const form = new FormData();
123
+ form.append('users', userData, userFilename);
124
+ form.append('connection_id', data.connection_id);
125
+ form.append('upsert', data.upsert === true ? 'true' : 'false');
126
+ form.append('send_completion_email', data.send_completion_email === false ? 'false' : 'true');
127
+
128
+ const headers = { ...options.headers, ...form.getHeaders() };
129
+ headers['Content-Type'] = 'multipart/form-data';
130
+
131
+ const promise = options.tokenProvider.getAccessToken().then(async (access_token) => {
132
+ try {
133
+ return await axios.post(url, form, {
134
+ headers: { ...headers, Authorization: `Bearer ${access_token}` },
135
+ });
136
+ } catch (err) {
146
137
  if (!err.response) {
147
- return Promise.reject(err);
138
+ throw err;
148
139
  }
149
140
 
150
- var res = err.response;
141
+ const res = err.response;
151
142
  // `superagent` uses the error parameter in callback on http errors.
152
143
  // the following code is intended to keep that behaviour (https://github.com/visionmedia/superagent/blob/master/lib/node/response.js#L170)
153
- var error = new Error('cannot POST' + ' ' + url + ' (' + res.status + ')');
144
+ const error = new Error(`${'cannot POST' + ' '}${url} (${res.status})`);
154
145
  error.status = res.status;
155
146
  error.method = 'POST';
156
147
  error.text = res.data.message || res.statusText || error.message;
157
- return Promise.reject(error);
158
- });
159
- });
148
+ throw error;
149
+ }
150
+ });
151
+
152
+ // Don't return a promise if a callback was given.
153
+ if (cb && cb instanceof Function) {
154
+ promise.then(cb.bind(null, null)).catch(cb);
160
155
 
161
- // Don't return a promise if a callback was given.
162
- if (cb && cb instanceof Function) {
163
- promise.then(cb.bind(null, null)).catch(cb);
156
+ return;
157
+ }
164
158
 
165
- return;
159
+ return promise;
166
160
  }
167
161
 
168
- return promise;
169
- };
162
+ /**
163
+ * Given a path to a file and a connection id, create a new job that imports the
164
+ * users contained in the file or JSON string and associate them with the given
165
+ * connection.
166
+ *
167
+ * @deprecated since version 2.26. It will be deleted in version 3.0.
168
+ * @example
169
+ * var params = {
170
+ * connection_id: '{CONNECTION_ID}',
171
+ * users: '{PATH_TO_USERS_FILE}' // or users_json: '{USERS_JSON_STRING}'
172
+ * };
173
+ *
174
+ * management.jobs.importUsers(params, function (err) {
175
+ * if (err) {
176
+ * // Handle error.
177
+ * }
178
+ * });
179
+ * @param {object} data Users import data.
180
+ * @param {string} data.connection_id connection_id of the connection to which users will be imported.
181
+ * @param {string} [data.users] Path to the users data file. Either users or users_json is mandatory.
182
+ * @param {string} [data.users_json] JSON data for the users.
183
+ * @param {boolean} [data.upsert] Whether to update users if they already exist (true) or to ignore them (false).
184
+ * @param {boolean} [data.send_completion_email] Whether to send a completion email to all tenant owners when the job is finished (true) or not (false).
185
+ * @param {Function} [cb] Callback function.
186
+ * @returns {Promise|undefined}
187
+ */
188
+ importUsers(data, cb) {
189
+ console.warn(
190
+ '"importUsers" has been deprecated as it was inconsistent with the API. Please, use "importUsersJob" which returns the response data directly.'
191
+ );
192
+ return this._importUsers(data, cb);
193
+ }
170
194
 
171
- /**
172
- * Given a path to a file and a connection id, create a new job that imports the
173
- * users contained in the file or JSON string and associate them with the given
174
- * connection.
175
- * @deprecated since version 2.26. It will be deleted in version 3.0.
176
- *
177
- * @method importUsers
178
- * @memberOf module:management.JobsManager.prototype
179
- *
180
- * @example
181
- * var params = {
182
- * connection_id: '{CONNECTION_ID}',
183
- * users: '{PATH_TO_USERS_FILE}' // or users_json: '{USERS_JSON_STRING}'
184
- * };
185
- *
186
- * management.jobs.importUsers(params, function (err) {
187
- * if (err) {
188
- * // Handle error.
189
- * }
190
- * });
191
- *
192
- * @param {Object} data Users import data.
193
- * @param {String} data.connection_id connection_id of the connection to which users will be imported.
194
- * @param {String} [data.users] Path to the users data file. Either users or users_json is mandatory.
195
- * @param {String} [data.users_json] JSON data for the users.
196
- * @param {Boolean} [data.upsert] Whether to update users if they already exist (true) or to ignore them (false).
197
- * @param {Boolean} [data.send_completion_email] Whether to send a completion email to all tenant owners when the job is finished (true) or not (false).
198
- * @param {Function} [cb] Callback function.
199
- *
200
- * @return {Promise|undefined}
201
- */
202
- JobsManager.prototype.importUsers = function(data, cb) {
203
- console.warn(
204
- '"importUsers" has been deprecated as it was inconsistent with the API. Please, use "importUsersJob" which returns the response data directly.'
205
- );
206
- return this._importUsers(data, cb);
207
- };
195
+ /**
196
+ * Given a path to a file and a connection id, create a new job that imports the
197
+ * users contained in the file or JSON string and associate them with the given
198
+ * connection.
199
+ *
200
+ * @example
201
+ * var params = {
202
+ * connection_id: '{CONNECTION_ID}',
203
+ * users: '{PATH_TO_USERS_FILE}' // or users_json: '{USERS_JSON_STRING}'
204
+ * };
205
+ *
206
+ * management.jobs.importUsers(params, function (err) {
207
+ * if (err) {
208
+ * // Handle error.
209
+ * }
210
+ * });
211
+ * @param {object} data Users import data.
212
+ * @param {string} data.connection_id connection_id of the connection to which users will be imported.
213
+ * @param {string} [data.users] Path to the users data file. Either users or users_json is mandatory.
214
+ * @param {string} [data.users_json] JSON data for the users.
215
+ * @param {boolean} [data.upsert] Whether to update users if they already exist (true) or to ignore them (false).
216
+ * @param {boolean} [data.send_completion_email] Whether to send a completion email to all tenant owners when the job is finished (true) or not (false).
217
+ * @param {Function} [cb] Callback function.
218
+ * @returns {Promise|undefined}
219
+ */
220
+ importUsersJob(data, cb) {
221
+ const promise = this._importUsers(data).then((response) => response.data);
208
222
 
209
- /**
210
- * Given a path to a file and a connection id, create a new job that imports the
211
- * users contained in the file or JSON string and associate them with the given
212
- * connection.
213
- *
214
- * @method importUsersJob
215
- * @memberOf module:management.JobsManager.prototype
216
- *
217
- * @example
218
- * var params = {
219
- * connection_id: '{CONNECTION_ID}',
220
- * users: '{PATH_TO_USERS_FILE}' // or users_json: '{USERS_JSON_STRING}'
221
- * };
222
- *
223
- * management.jobs.importUsers(params, function (err) {
224
- * if (err) {
225
- * // Handle error.
226
- * }
227
- * });
228
- *
229
- * @param {Object} data Users import data.
230
- * @param {String} data.connection_id connection_id of the connection to which users will be imported.
231
- * @param {String} [data.users] Path to the users data file. Either users or users_json is mandatory.
232
- * @param {String} [data.users_json] JSON data for the users.
233
- * @param {Boolean} [data.upsert] Whether to update users if they already exist (true) or to ignore them (false).
234
- * @param {Boolean} [data.send_completion_email] Whether to send a completion email to all tenant owners when the job is finished (true) or not (false).
235
- * @param {Function} [cb] Callback function.
236
- *
237
- * @return {Promise|undefined}
238
- */
239
- JobsManager.prototype.importUsersJob = function(data, cb) {
240
- var promise = this._importUsers(data).then(response => response.data);
223
+ // Don't return a promise if a callback was given.
224
+ if (cb && cb instanceof Function) {
225
+ promise.then(cb.bind(null, null)).catch(cb);
241
226
 
242
- // Don't return a promise if a callback was given.
243
- if (cb && cb instanceof Function) {
244
- promise.then(cb.bind(null, null)).catch(cb);
227
+ return;
228
+ }
245
229
 
246
- return;
230
+ return promise;
247
231
  }
248
232
 
249
- return promise;
250
- };
233
+ /**
234
+ * Export all users to a file using a long running job.
235
+ *
236
+ * @example
237
+ * var data = {
238
+ * connection_id: 'con_0000000000000001',
239
+ * format: 'csv',
240
+ * limit: 5,
241
+ * fields: [
242
+ * {
243
+ * "name": "user_id"
244
+ * },
245
+ * {
246
+ * "name": "name"
247
+ * },
248
+ * {
249
+ * "name": "email"
250
+ * },
251
+ * {
252
+ * "name": "identities[0].connection",
253
+ * "export_as": "provider"
254
+ * },
255
+ * {
256
+ * "name": "user_metadata.some_field"
257
+ * }
258
+ * ]
259
+ * }
260
+ *
261
+ * management.jobs.exportUsers(data, function (err, results) {
262
+ * if (err) {
263
+ * // Handle error.
264
+ * }
265
+ *
266
+ * // Retrieved job.
267
+ * console.log(results);
268
+ * });
269
+ * @param {object} data Users export data.
270
+ * @param {string} [data.connection_id] The connection id of the connection from which users will be exported
271
+ * @param {string} [data.format] The format of the file. Valid values are: "json" and "csv".
272
+ * @param {number} [data.limit] Limit the number of records.
273
+ * @param {object[]} [data.fields] A list of fields to be included in the CSV. If omitted, a set of predefined fields will be exported.
274
+ * @param {Function} [cb] Callback function.
275
+ * @returns {Promise|undefined}
276
+ */
277
+ exportUsers(data, cb) {
278
+ if (cb && cb instanceof Function) {
279
+ return this.usersExports.create(data, cb);
280
+ }
251
281
 
252
- /**
253
- * Export all users to a file using a long running job.
254
- *
255
- * @method exportUsers
256
- * @memberOf module:management.JobsManager.prototype
257
- *
258
- * @example
259
- * var data = {
260
- * connection_id: 'con_0000000000000001',
261
- * format: 'csv',
262
- * limit: 5,
263
- * fields: [
264
- * {
265
- * "name": "user_id"
266
- * },
267
- * {
268
- * "name": "name"
269
- * },
270
- * {
271
- * "name": "email"
272
- * },
273
- * {
274
- * "name": "identities[0].connection",
275
- * "export_as": "provider"
276
- * },
277
- * {
278
- * "name": "user_metadata.some_field"
279
- * }
280
- * ]
281
- * }
282
- *
283
- * management.jobs.exportUsers(data, function (err, results) {
284
- * if (err) {
285
- * // Handle error.
286
- * }
287
- *
288
- * // Retrieved job.
289
- * console.log(results);
290
- * });
291
- *
292
- * @param {Object} data Users export data.
293
- * @param {String} [data.connection_id] The connection id of the connection from which users will be exported
294
- * @param {String} [data.format] The format of the file. Valid values are: "json" and "csv".
295
- * @param {Number} [data.limit] Limit the number of records.
296
- * @param {Object[]} [data.fields] A list of fields to be included in the CSV. If omitted, a set of predefined fields will be exported.
297
- * @param {Function} [cb] Callback function.
298
- *
299
- * @return {Promise|undefined}
300
- */
301
- JobsManager.prototype.exportUsers = function(data, cb) {
302
- if (cb && cb instanceof Function) {
303
- return this.usersExports.create(data, cb);
282
+ return this.usersExports.create(data);
304
283
  }
305
284
 
306
- return this.usersExports.create(data);
307
- };
285
+ /**
286
+ * Given a job ID, retrieve the failed/errored items
287
+ *
288
+ * @example
289
+ * var params = {
290
+ * id: '{JOB_ID}'
291
+ * };
292
+ *
293
+ * management.jobs.errors(params, function (err, job) {
294
+ * if (err) {
295
+ * // Handle error.
296
+ * }
297
+ *
298
+ * // Retrieved job.
299
+ * console.log(job);
300
+ * });
301
+ * @param {object} params Job parameters.
302
+ * @param {string} params.id Job ID.
303
+ * @param {Function} [cb] Callback function.
304
+ * @returns {Promise|undefined}
305
+ */
306
+ errors(params, cb) {
307
+ if (!params.id || typeof params.id !== 'string') {
308
+ throw new ArgumentError('The id parameter must be a valid job id');
309
+ }
308
310
 
309
- /**
310
- * Given a job ID, retrieve the failed/errored items
311
- *
312
- * @method errors
313
- * @memberOf module:management.JobsManager.prototype
314
- *
315
- * @example
316
- * var params = {
317
- * id: '{JOB_ID}'
318
- * };
319
- *
320
- * management.jobs.errors(params, function (err, job) {
321
- * if (err) {
322
- * // Handle error.
323
- * }
324
- *
325
- * // Retrieved job.
326
- * console.log(job);
327
- * });
328
- *
329
- * @param {Object} params Job parameters.
330
- * @param {String} params.id Job ID.
331
- * @param {Function} [cb] Callback function.
332
- *
333
- * @return {Promise|undefined}
334
- */
335
- JobsManager.prototype.errors = function(params, cb) {
336
- if (!params.id || typeof params.id !== 'string') {
337
- throw new ArgumentError('The id parameter must be a valid job id');
338
- }
311
+ if (cb && cb instanceof Function) {
312
+ return this.jobErrors.get(params, cb);
313
+ }
339
314
 
340
- if (cb && cb instanceof Function) {
341
- return this.jobErrors.get(params, cb);
315
+ // Return a promise.
316
+ return this.jobErrors.get(params);
342
317
  }
343
318
 
344
- // Return a promise.
345
- return this.jobErrors.get(params);
346
- };
319
+ /**
320
+ * Send a verification email to a user.
321
+ *
322
+ * @example
323
+ * var params = {
324
+ * user_id: '{USER_ID}'
325
+ * };
326
+ *
327
+ * management.jobs.verifyEmail(params, function (err) {
328
+ * if (err) {
329
+ * // Handle error.
330
+ * }
331
+ * });
332
+ * @param {object} data User data object.
333
+ * @param {string} data.user_id ID of the user to be verified.
334
+ * @param {string} [data.organization_id] Organization ID
335
+ * @param {string} [data.client_id] client_id of the client (application). If no value provided, the global Client ID will be used.
336
+ * @param {object} [data.identity] Used to verify secondary, federated, and passwordless-email identities.
337
+ * @param {string} data.identity.user_id user_id of the identity.
338
+ * @param {string} data.identity.provider provider of the identity.
339
+ * @param {Function} [cb] Callback function.
340
+ * @returns {Promise|undefined}
341
+ */
342
+ verifyEmail(data, cb) {
343
+ if (!data.user_id || typeof data.user_id !== 'string') {
344
+ throw new ArgumentError('Must specify a user ID');
345
+ }
347
346
 
348
- /**
349
- * Send a verification email to a user.
350
- *
351
- * @method verifyEmail
352
- * @memberOf module:management.JobsManager.prototype
353
- *
354
- * @example
355
- * var params = {
356
- * user_id: '{USER_ID}'
357
- * };
358
- *
359
- * management.jobs.verifyEmail(function (err) {
360
- * if (err) {
361
- * // Handle error.
362
- * }
363
- * });
364
- *
365
- * @param {Object} data User data object.
366
- * @param {String} data.user_id ID of the user to be verified.
367
- * @param {String} [data.organization_id] Organization ID
368
- * @param {String} [data.client_id] client_id of the client (application). If no value provided, the global Client ID will be used.
369
- * @param {Object} [data.identity] Used to verify secondary, federated, and passwordless-email identities.
370
- * @param {String} data.identity.user_id user_id of the identity.
371
- * @param {String} data.identity.provider provider of the identity.
372
- * @param {Function} [cb] Callback function.
373
- *
374
- * @return {Promise|undefined}
375
- */
376
- JobsManager.prototype.verifyEmail = function(data, cb) {
377
- if (!data.user_id || typeof data.user_id !== 'string') {
378
- throw new ArgumentError('Must specify a user ID');
379
- }
347
+ if (cb && cb instanceof Function) {
348
+ return this.jobs.create({ id: 'verification-email' }, data, cb);
349
+ }
380
350
 
381
- if (cb && cb instanceof Function) {
382
- return this.jobs.create({ id: 'verification-email' }, data, cb);
351
+ // Return a promise.
352
+ return this.jobs.create({ id: 'verification-email' }, data);
383
353
  }
384
-
385
- // Return a promise.
386
- return this.jobs.create({ id: 'verification-email' }, data);
387
- };
354
+ }
388
355
 
389
356
  module.exports = JobsManager;