auth0 2.36.2 → 2.39.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.
- package/CHANGELOG.md +41 -0
- package/README.md +33 -11
- package/package.json +22 -14
- package/src/Auth0RestClient.js +72 -71
- package/src/RetryRestClient.js +78 -81
- package/src/auth/DatabaseAuthenticator.js +242 -259
- package/src/auth/OAUthWithIDTokenValidation.js +99 -103
- package/src/auth/OAuthAuthenticator.js +325 -344
- package/src/auth/PasswordlessAuthenticator.js +238 -252
- package/src/auth/TokensManager.js +231 -246
- package/src/auth/UsersManager.js +149 -160
- package/src/auth/idToken.js +22 -19
- package/src/auth/index.js +510 -581
- package/src/errors.js +23 -23
- package/src/index.js +3 -2
- package/src/management/ActionsManager.js +510 -584
- package/src/management/BlacklistedTokensManager.js +77 -84
- package/src/management/BrandingManager.js +141 -163
- package/src/management/ClientGrantsManager.js +132 -145
- package/src/management/ClientsManager.js +145 -161
- package/src/management/ConnectionsManager.js +215 -204
- package/src/management/CustomDomainsManager.js +140 -157
- package/src/management/DeviceCredentialsManager.js +95 -111
- package/src/management/EmailProviderManager.js +110 -128
- package/src/management/EmailTemplatesManager.js +96 -112
- package/src/management/GrantsManager.js +94 -101
- package/src/management/GuardianManager.js +381 -455
- package/src/management/HooksManager.js +283 -325
- package/src/management/JobsManager.js +310 -343
- package/src/management/LogStreamsManager.js +142 -158
- package/src/management/LogsManager.js +92 -99
- package/src/management/ManagementTokenProvider.js +112 -120
- package/src/management/MigrationsManager.js +81 -90
- package/src/management/OrganizationsManager.js +686 -761
- package/src/management/PromptsManager.js +160 -182
- package/src/management/ResourceServersManager.js +143 -160
- package/src/management/RolesManager.js +323 -369
- package/src/management/RulesConfigsManager.js +94 -110
- package/src/management/RulesManager.js +154 -176
- package/src/management/StatsManager.js +87 -103
- package/src/management/TenantManager.js +81 -97
- package/src/management/TicketsManager.js +107 -115
- package/src/management/UserBlocksManager.js +135 -162
- package/src/management/UsersManager.js +729 -852
- package/src/management/index.js +3094 -3619
- package/src/utils.js +31 -60
|
@@ -1,389 +1,356 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var fs = require('fs');
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const FormData = require('form-data');
|
|
3
|
+
const fs = require('fs');
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
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
|
-
|
|
55
|
-
options
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
*
|
|
63
|
-
* {@link https://auth0.com/docs/api/v2#!/Jobs/:id/errors Errors endpoint}.
|
|
81
|
+
* Get a job by its ID.
|
|
64
82
|
*
|
|
65
|
-
* @
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
return this.jobs.get(params
|
|
110
|
+
// Return a promise.
|
|
111
|
+
return this.jobs.get(params);
|
|
121
112
|
}
|
|
122
113
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
138
|
+
throw err;
|
|
148
139
|
}
|
|
149
140
|
|
|
150
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
promise.then(cb.bind(null, null)).catch(cb);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
164
158
|
|
|
165
|
-
return;
|
|
159
|
+
return promise;
|
|
166
160
|
}
|
|
167
161
|
|
|
168
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
211
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
promise.then(cb.bind(null, null)).catch(cb);
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
245
229
|
|
|
246
|
-
return;
|
|
230
|
+
return promise;
|
|
247
231
|
}
|
|
248
232
|
|
|
249
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
341
|
-
return this.jobErrors.get(params
|
|
315
|
+
// Return a promise.
|
|
316
|
+
return this.jobErrors.get(params);
|
|
342
317
|
}
|
|
343
318
|
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
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
|
-
|
|
382
|
-
return this.jobs.create({ id: 'verification-email' }, data
|
|
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;
|