auth0 3.3.0 → 4.0.0-beta.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/README.md +19 -15
- package/package.json +47 -33
- package/CHANGELOG.md +0 -673
- package/src/Auth0RestClient.js +0 -123
- package/src/RetryRestClient.js +0 -105
- package/src/auth/DatabaseAuthenticator.js +0 -282
- package/src/auth/OAUthWithIDTokenValidation.js +0 -124
- package/src/auth/OAuthAuthenticator.js +0 -405
- package/src/auth/PasswordlessAuthenticator.js +0 -303
- package/src/auth/TokensManager.js +0 -254
- package/src/auth/UsersManager.js +0 -161
- package/src/auth/clientAuthentication.js +0 -86
- package/src/auth/idToken.js +0 -167
- package/src/auth/index.js +0 -573
- package/src/errors.js +0 -60
- package/src/index.js +0 -11
- package/src/index.mjs +0 -11
- package/src/management/ActionsManager.js +0 -526
- package/src/management/AttackProtectionManager.js +0 -158
- package/src/management/BaseManager.js +0 -41
- package/src/management/BlacklistedTokensManager.js +0 -67
- package/src/management/BrandingManager.js +0 -250
- package/src/management/ClientCredentialsManager.js +0 -112
- package/src/management/ClientGrantsManager.js +0 -124
- package/src/management/ClientsManager.js +0 -184
- package/src/management/ConnectionsManager.js +0 -213
- package/src/management/CustomDomainsManager.js +0 -141
- package/src/management/DeviceCredentialsManager.js +0 -91
- package/src/management/EmailProviderManager.js +0 -101
- package/src/management/EmailTemplatesManager.js +0 -90
- package/src/management/GrantsManager.js +0 -84
- package/src/management/GuardianManager.js +0 -361
- package/src/management/HooksManager.js +0 -295
- package/src/management/JobsManager.js +0 -324
- package/src/management/LogStreamsManager.js +0 -136
- package/src/management/LogsManager.js +0 -82
- package/src/management/ManagementTokenProvider.js +0 -144
- package/src/management/MigrationsManager.js +0 -76
- package/src/management/OrganizationsManager.js +0 -721
- package/src/management/PromptsManager.js +0 -162
- package/src/management/ResourceServersManager.js +0 -143
- package/src/management/RolesManager.js +0 -329
- package/src/management/RulesConfigsManager.js +0 -86
- package/src/management/RulesManager.js +0 -148
- package/src/management/StatsManager.js +0 -84
- package/src/management/TenantManager.js +0 -76
- package/src/management/TicketsManager.js +0 -104
- package/src/management/UserBlocksManager.js +0 -121
- package/src/management/UsersManager.js +0 -882
- package/src/management/index.js +0 -3405
- package/src/utils.js +0 -60
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
const { ArgumentError } = require('rest-facade');
|
|
2
|
-
const BaseManager = require('./BaseManager');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The hooks manager class provides a simple abstraction for performing CRUD operations
|
|
6
|
-
* on Auth0 HooksManagers.
|
|
7
|
-
*/
|
|
8
|
-
class HooksManager extends BaseManager {
|
|
9
|
-
/**
|
|
10
|
-
* @param {object} options The client options.
|
|
11
|
-
* @param {string} options.baseUrl The URL of the API.
|
|
12
|
-
* @param {object} [options.headers] Headers to be included in all requests.
|
|
13
|
-
* @param {object} [options.retry] Retry Policy Config
|
|
14
|
-
*/
|
|
15
|
-
constructor(options) {
|
|
16
|
-
super(options);
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Provides an abstraction layer for performing CRUD operations on
|
|
20
|
-
* {@link https://auth0.com/docs/api/v2#!/HooksManagers Auth0 HooksManagers}.
|
|
21
|
-
*
|
|
22
|
-
* @type {external:RestClient}
|
|
23
|
-
*/
|
|
24
|
-
this.resource = this._getRestClient('/hooks/:id');
|
|
25
|
-
|
|
26
|
-
this.secrets = this._getRestClient('/hooks/:id/secrets');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Create a new hook.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* management.hooks.create(data, function (err) {
|
|
34
|
-
* if (err) {
|
|
35
|
-
* // Handle error.
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* // Hook created.
|
|
39
|
-
* });
|
|
40
|
-
* @param {object} data Hook data object.
|
|
41
|
-
* @param {Function} [cb] Callback function.
|
|
42
|
-
* @returns {Promise|undefined}
|
|
43
|
-
*/
|
|
44
|
-
create(...args) {
|
|
45
|
-
return this.resource.create(...args);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Get all hooks.
|
|
50
|
-
*
|
|
51
|
-
* @example <caption>
|
|
52
|
-
* This method takes an optional object as first argument that may be used to
|
|
53
|
-
* specify pagination settings. If pagination options are not present,
|
|
54
|
-
* the first page of a limited number of results will be returned.
|
|
55
|
-
* </caption>
|
|
56
|
-
*
|
|
57
|
-
* // Pagination settings.
|
|
58
|
-
* var params = {
|
|
59
|
-
* per_page: 10,
|
|
60
|
-
* page: 0
|
|
61
|
-
* };
|
|
62
|
-
*
|
|
63
|
-
* management.hooks.getAll(params, function (err, hooks) {
|
|
64
|
-
* console.log(hooks.length);
|
|
65
|
-
* });
|
|
66
|
-
* @param {object} [params] Hooks parameters.
|
|
67
|
-
* @param {number} [params.per_page] Number of results per page.
|
|
68
|
-
* @param {number} [params.page] Page number, zero indexed.
|
|
69
|
-
* @param {Function} [cb] Callback function.
|
|
70
|
-
* @returns {Promise|undefined}
|
|
71
|
-
*/
|
|
72
|
-
getAll(...args) {
|
|
73
|
-
return this.resource.getAll(...args);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get an Auth0 hook.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* management.hooks.get({ id: HOOK_ID }, function (err, hook) {
|
|
81
|
-
* if (err) {
|
|
82
|
-
* // Handle error.
|
|
83
|
-
* }
|
|
84
|
-
*
|
|
85
|
-
* console.log(hook);
|
|
86
|
-
* });
|
|
87
|
-
* @param {object} params Hook parameters.
|
|
88
|
-
* @param {string} params.id Hook ID.
|
|
89
|
-
* @param {Function} [cb] Callback function.
|
|
90
|
-
* @returns {Promise|undefined}
|
|
91
|
-
*/
|
|
92
|
-
get(...args) {
|
|
93
|
-
return this.resource.get(...args);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Update an existing hook.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* var data = { name: 'New name' };
|
|
101
|
-
* var params = { id: HOOK_ID };
|
|
102
|
-
*
|
|
103
|
-
* // Using auth0 instance.
|
|
104
|
-
* management.updateHook(params, data, function (err, hook) {
|
|
105
|
-
* if (err) {
|
|
106
|
-
* // Handle error.
|
|
107
|
-
* }
|
|
108
|
-
*
|
|
109
|
-
* console.log(hook.name); // 'New name'
|
|
110
|
-
* });
|
|
111
|
-
*
|
|
112
|
-
* // Using the hooks manager directly.
|
|
113
|
-
* management.hooks.update(params, data, function (err, hook) {
|
|
114
|
-
* if (err) {
|
|
115
|
-
* // Handle error.
|
|
116
|
-
* }
|
|
117
|
-
*
|
|
118
|
-
* console.log(hook.name); // 'New name'
|
|
119
|
-
* });
|
|
120
|
-
* @param {object} params Hook parameters.
|
|
121
|
-
* @param {string} params.id Hook ID.
|
|
122
|
-
* @param {object} data Updated hook data.
|
|
123
|
-
* @param {Function} [cb] Callback function.
|
|
124
|
-
* @returns {Promise|undefined}
|
|
125
|
-
*/
|
|
126
|
-
update(...args) {
|
|
127
|
-
return this.resource.patch(...args);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Delete an existing hook.
|
|
132
|
-
*
|
|
133
|
-
* @example
|
|
134
|
-
* management.hooks.delete({ id: HOOK_ID }, function (err) {
|
|
135
|
-
* if (err) {
|
|
136
|
-
* // Handle error.
|
|
137
|
-
* }
|
|
138
|
-
*
|
|
139
|
-
* // Hook deleted.
|
|
140
|
-
* });
|
|
141
|
-
* @param {object} params Hook parameters.
|
|
142
|
-
* @param {string} params.id Hook ID.
|
|
143
|
-
* @param {Function} [cb] Callback function.
|
|
144
|
-
* @returns {Promise|undefined}
|
|
145
|
-
*/
|
|
146
|
-
delete(...args) {
|
|
147
|
-
return this.resource.delete(...args);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Get Hook secrets
|
|
152
|
-
*
|
|
153
|
-
* @example <caption>
|
|
154
|
-
* This method takes a first argument as the hookId and returns the secrets for the hook. The secret values will be hidden.
|
|
155
|
-
* </caption>
|
|
156
|
-
*
|
|
157
|
-
* var params = {id : 'HOOK_ID'}
|
|
158
|
-
*
|
|
159
|
-
* management.hooks.getSecrets( {id : 'HOOK_ID'}, function (err, secrets) {
|
|
160
|
-
* console.log(secrets);
|
|
161
|
-
* });
|
|
162
|
-
* @param {object} params Hook parameters.
|
|
163
|
-
* @param {string} params.id ID of the Hook.
|
|
164
|
-
* @param {Function} [cb] Callback function.
|
|
165
|
-
* @returns {Promise|undefined}
|
|
166
|
-
*/
|
|
167
|
-
getSecrets(params, callback) {
|
|
168
|
-
return this.secrets.getAll(params, callback);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Add secrets in a hook
|
|
173
|
-
*
|
|
174
|
-
* @example
|
|
175
|
-
* var params = { id :'HOOK_ID'};
|
|
176
|
-
* var data = { "DB_USER" : "jdoe", "DB_PASS": "password123!"};
|
|
177
|
-
*
|
|
178
|
-
* management.hooks.addSecrets(params, data, function (err, secrets) {
|
|
179
|
-
* if (err) {
|
|
180
|
-
* // Handle error.
|
|
181
|
-
* }
|
|
182
|
-
*
|
|
183
|
-
* // secrets added.
|
|
184
|
-
* });
|
|
185
|
-
* @param {object} params Hook parameters.
|
|
186
|
-
* @param {string} params.id ID of the Hook.
|
|
187
|
-
* @param {object} data object containing secrets as key/value pairs
|
|
188
|
-
* @param {Function} [cb] Callback function.
|
|
189
|
-
* @returns {Promise|undefined}
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
addSecrets(params, data, cb) {
|
|
193
|
-
params = params || {};
|
|
194
|
-
data = data || {};
|
|
195
|
-
|
|
196
|
-
// Require an ID.
|
|
197
|
-
if (!params.id) {
|
|
198
|
-
throw new ArgumentError('The id passed in params cannot be null or undefined');
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (typeof params.id !== 'string') {
|
|
202
|
-
throw new ArgumentError('The hook Id has to be a string');
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
if (cb && cb instanceof Function) {
|
|
206
|
-
return this.secrets.create(params, data, cb);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return this.secrets.create(params, data);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Update secrets in a hook
|
|
214
|
-
*
|
|
215
|
-
* @example
|
|
216
|
-
* var params = { id :'HOOK_ID'};
|
|
217
|
-
* var data = { "DB_USER" : "jdoe", "DB_PASS": "password123!"};
|
|
218
|
-
*
|
|
219
|
-
* management.hooks.updateSecrets(params, data, function (err, secrets) {
|
|
220
|
-
* if (err) {
|
|
221
|
-
* // Handle error.
|
|
222
|
-
* }
|
|
223
|
-
*
|
|
224
|
-
* // secrets updated.
|
|
225
|
-
* });
|
|
226
|
-
* @param {object} params Hook parameters.
|
|
227
|
-
* @param {string} params.id ID of the Hook.
|
|
228
|
-
* @param {object} data object containing secrets as key/value pairs
|
|
229
|
-
* @param {Function} [cb] Callback function.
|
|
230
|
-
* @returns {Promise|undefined}
|
|
231
|
-
*/
|
|
232
|
-
|
|
233
|
-
updateSecrets(params, data, cb) {
|
|
234
|
-
params = params || {};
|
|
235
|
-
data = data || {};
|
|
236
|
-
|
|
237
|
-
// Require an ID.
|
|
238
|
-
if (!params.id) {
|
|
239
|
-
throw new ArgumentError('The id passed in params cannot be null or undefined');
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
if (typeof params.id !== 'string') {
|
|
243
|
-
throw new ArgumentError('The hook Id has to be a string');
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (cb && cb instanceof Function) {
|
|
247
|
-
return this.secrets.patch(params, data, cb);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return this.secrets.patch(params, data);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Remove secrets from a hook
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* var params = { id :'HOOK_ID'};
|
|
258
|
-
* var data =["DB_PASS"];
|
|
259
|
-
*
|
|
260
|
-
* management.hooks.removeSecrets(params, data, function (err, hook) {
|
|
261
|
-
* if (err) {
|
|
262
|
-
* // Handle error.
|
|
263
|
-
* }
|
|
264
|
-
*
|
|
265
|
-
* // secrets added.
|
|
266
|
-
* });
|
|
267
|
-
* @param {object} params Hook parameters.
|
|
268
|
-
* @param {string} params.id ID of the Hook.
|
|
269
|
-
* @param {object} data Array of secret names
|
|
270
|
-
* @param {Function} [cb] Callback function.
|
|
271
|
-
* @returns {Promise|undefined}
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
removeSecrets(params, data, cb) {
|
|
275
|
-
params = params || {};
|
|
276
|
-
data = data || {};
|
|
277
|
-
|
|
278
|
-
// Require an ID.
|
|
279
|
-
if (!params.id) {
|
|
280
|
-
throw new ArgumentError('The id passed in params cannot be null or undefined');
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (typeof params.id !== 'string') {
|
|
284
|
-
throw new ArgumentError('The hook Id has to be a string');
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (cb && cb instanceof Function) {
|
|
288
|
-
return this.secrets.delete(params, data, cb);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
return this.secrets.delete(params, data);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
module.exports = HooksManager;
|
|
@@ -1,324 +0,0 @@
|
|
|
1
|
-
const axios = require('axios');
|
|
2
|
-
const FormData = require('form-data');
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
const { ArgumentError } = require('rest-facade');
|
|
6
|
-
const BaseManager = require('./BaseManager');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Abstract the creation as well as the retrieval of async jobs.
|
|
10
|
-
*/
|
|
11
|
-
class JobsManager extends BaseManager {
|
|
12
|
-
/**
|
|
13
|
-
* @param {object} options The client options.
|
|
14
|
-
* @param {string} options.baseUrl The URL of the API.
|
|
15
|
-
* @param {object} [options.headers] Headers to be included in all requests.
|
|
16
|
-
* @param {object} [options.retry] Retry Policy Config
|
|
17
|
-
*/
|
|
18
|
-
constructor(options) {
|
|
19
|
-
super(options);
|
|
20
|
-
|
|
21
|
-
this.options = options;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Provides an abstraction layer for consuming the
|
|
25
|
-
* {@link https://auth0.com/docs/api/v2#!/Jobs Jobs endpoint}.
|
|
26
|
-
*
|
|
27
|
-
* @type {external:RestClient}
|
|
28
|
-
*/
|
|
29
|
-
this.jobs = this._getRestClient('/jobs/:id');
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Provides an abstraction layer for consuming the
|
|
33
|
-
* {@link https://auth0.com/docs/api/v2#!/Jobs/:id/errors Errors endpoint}.
|
|
34
|
-
*
|
|
35
|
-
* @type {external:RestClient}
|
|
36
|
-
*/
|
|
37
|
-
this.jobErrors = this._getRestClient('/jobs/:id/errors');
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Provides an abstraction layer for consuming the
|
|
41
|
-
* {@link https://auth0.com/docs/api/v2#!/Jobs/post_users_exports Create job to export users endpoint}
|
|
42
|
-
*
|
|
43
|
-
* @type {external:RestClient}
|
|
44
|
-
*/
|
|
45
|
-
this.usersExports = this._getRestClient('/jobs/users-exports');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Get a job by its ID.
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* var params = {
|
|
53
|
-
* id: '{JOB_ID}'
|
|
54
|
-
* };
|
|
55
|
-
*
|
|
56
|
-
* management.jobs.get(params, function (err, job) {
|
|
57
|
-
* if (err) {
|
|
58
|
-
* // Handle error.
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* // Retrieved job.
|
|
62
|
-
* console.log(job);
|
|
63
|
-
* });
|
|
64
|
-
* @param {object} params Job parameters.
|
|
65
|
-
* @param {string} params.id Job ID.
|
|
66
|
-
* @param {Function} [cb] Callback function.
|
|
67
|
-
* @returns {Promise|undefined}
|
|
68
|
-
*/
|
|
69
|
-
get(params, cb) {
|
|
70
|
-
if (!params.id || typeof params.id !== 'string') {
|
|
71
|
-
throw new ArgumentError('The id parameter must be a valid job id');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (cb && cb instanceof Function) {
|
|
75
|
-
return this.jobs.get(params, cb);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Return a promise.
|
|
79
|
-
return this.jobs.get(params);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
_importUsers(data, cb) {
|
|
83
|
-
const { options } = this;
|
|
84
|
-
const url = `${options.baseUrl}/jobs/users-imports`;
|
|
85
|
-
const userData = data.users_json
|
|
86
|
-
? Buffer.from(data.users_json)
|
|
87
|
-
: fs.createReadStream(data.users);
|
|
88
|
-
const userFilename = data.users_json ? 'users.json' : data.users;
|
|
89
|
-
|
|
90
|
-
const form = new FormData();
|
|
91
|
-
form.append('users', userData, userFilename);
|
|
92
|
-
form.append('connection_id', data.connection_id);
|
|
93
|
-
form.append('upsert', data.upsert === true ? 'true' : 'false');
|
|
94
|
-
form.append('send_completion_email', data.send_completion_email === false ? 'false' : 'true');
|
|
95
|
-
|
|
96
|
-
const headers = { ...options.headers, ...form.getHeaders() };
|
|
97
|
-
headers['Content-Type'] = 'multipart/form-data';
|
|
98
|
-
|
|
99
|
-
const promise = options.tokenProvider.getAccessToken().then(async (access_token) => {
|
|
100
|
-
try {
|
|
101
|
-
return await axios.post(url, form, {
|
|
102
|
-
headers: { ...headers, Authorization: `Bearer ${access_token}` },
|
|
103
|
-
});
|
|
104
|
-
} catch (err) {
|
|
105
|
-
if (!err.response) {
|
|
106
|
-
throw err;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const res = err.response;
|
|
110
|
-
// `superagent` uses the error parameter in callback on http errors.
|
|
111
|
-
// the following code is intended to keep that behaviour (https://github.com/visionmedia/superagent/blob/master/lib/node/response.js#L170)
|
|
112
|
-
const error = new Error(`${'cannot POST' + ' '}${url} (${res.status})`);
|
|
113
|
-
error.status = res.status;
|
|
114
|
-
error.method = 'POST';
|
|
115
|
-
error.text = res.data.message || res.statusText || error.message;
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// Don't return a promise if a callback was given.
|
|
121
|
-
if (cb && cb instanceof Function) {
|
|
122
|
-
promise.then(cb.bind(null, null)).catch(cb);
|
|
123
|
-
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return promise;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Given a path to a file and a connection id, create a new job that imports the
|
|
132
|
-
* users contained in the file or JSON string and associate them with the given
|
|
133
|
-
* connection.
|
|
134
|
-
*
|
|
135
|
-
* @deprecated since version 2.26. It will be deleted in version 3.0.
|
|
136
|
-
* @example
|
|
137
|
-
* var params = {
|
|
138
|
-
* connection_id: '{CONNECTION_ID}',
|
|
139
|
-
* users: '{PATH_TO_USERS_FILE}' // or users_json: '{USERS_JSON_STRING}'
|
|
140
|
-
* };
|
|
141
|
-
*
|
|
142
|
-
* management.jobs.importUsers(params, function (err) {
|
|
143
|
-
* if (err) {
|
|
144
|
-
* // Handle error.
|
|
145
|
-
* }
|
|
146
|
-
* });
|
|
147
|
-
* @param {object} data Users import data.
|
|
148
|
-
* @param {string} data.connection_id connection_id of the connection to which users will be imported.
|
|
149
|
-
* @param {string} [data.users] Path to the users data file. Either users or users_json is mandatory.
|
|
150
|
-
* @param {string} [data.users_json] JSON data for the users.
|
|
151
|
-
* @param {boolean} [data.upsert] Whether to update users if they already exist (true) or to ignore them (false).
|
|
152
|
-
* @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).
|
|
153
|
-
* @param {Function} [cb] Callback function.
|
|
154
|
-
* @returns {Promise|undefined}
|
|
155
|
-
*/
|
|
156
|
-
importUsers(data, cb) {
|
|
157
|
-
console.warn(
|
|
158
|
-
'"importUsers" has been deprecated as it was inconsistent with the API. Please, use "importUsersJob" which returns the response data directly.'
|
|
159
|
-
);
|
|
160
|
-
return this._importUsers(data, cb);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Given a path to a file and a connection id, create a new job that imports the
|
|
165
|
-
* users contained in the file or JSON string and associate them with the given
|
|
166
|
-
* connection.
|
|
167
|
-
*
|
|
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
|
-
importUsersJob(data, cb) {
|
|
189
|
-
const promise = this._importUsers(data).then((response) => response.data);
|
|
190
|
-
|
|
191
|
-
// Don't return a promise if a callback was given.
|
|
192
|
-
if (cb && cb instanceof Function) {
|
|
193
|
-
promise.then(cb.bind(null, null)).catch(cb);
|
|
194
|
-
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return promise;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Export all users to a file using a long running job.
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* var data = {
|
|
206
|
-
* connection_id: 'con_0000000000000001',
|
|
207
|
-
* format: 'csv',
|
|
208
|
-
* limit: 5,
|
|
209
|
-
* fields: [
|
|
210
|
-
* {
|
|
211
|
-
* "name": "user_id"
|
|
212
|
-
* },
|
|
213
|
-
* {
|
|
214
|
-
* "name": "name"
|
|
215
|
-
* },
|
|
216
|
-
* {
|
|
217
|
-
* "name": "email"
|
|
218
|
-
* },
|
|
219
|
-
* {
|
|
220
|
-
* "name": "identities[0].connection",
|
|
221
|
-
* "export_as": "provider"
|
|
222
|
-
* },
|
|
223
|
-
* {
|
|
224
|
-
* "name": "user_metadata.some_field"
|
|
225
|
-
* }
|
|
226
|
-
* ]
|
|
227
|
-
* }
|
|
228
|
-
*
|
|
229
|
-
* management.jobs.exportUsers(data, function (err, results) {
|
|
230
|
-
* if (err) {
|
|
231
|
-
* // Handle error.
|
|
232
|
-
* }
|
|
233
|
-
*
|
|
234
|
-
* // Retrieved job.
|
|
235
|
-
* console.log(results);
|
|
236
|
-
* });
|
|
237
|
-
* @param {object} data Users export data.
|
|
238
|
-
* @param {string} [data.connection_id] The connection id of the connection from which users will be exported
|
|
239
|
-
* @param {string} [data.format] The format of the file. Valid values are: "json" and "csv".
|
|
240
|
-
* @param {number} [data.limit] Limit the number of records.
|
|
241
|
-
* @param {object[]} [data.fields] A list of fields to be included in the CSV. If omitted, a set of predefined fields will be exported.
|
|
242
|
-
* @param {Function} [cb] Callback function.
|
|
243
|
-
* @returns {Promise|undefined}
|
|
244
|
-
*/
|
|
245
|
-
exportUsers(data, cb) {
|
|
246
|
-
if (cb && cb instanceof Function) {
|
|
247
|
-
return this.usersExports.create(data, cb);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return this.usersExports.create(data);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Given a job ID, retrieve the failed/errored items
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* var params = {
|
|
258
|
-
* id: '{JOB_ID}'
|
|
259
|
-
* };
|
|
260
|
-
*
|
|
261
|
-
* management.jobs.errors(params, function (err, job) {
|
|
262
|
-
* if (err) {
|
|
263
|
-
* // Handle error.
|
|
264
|
-
* }
|
|
265
|
-
*
|
|
266
|
-
* // Retrieved job.
|
|
267
|
-
* console.log(job);
|
|
268
|
-
* });
|
|
269
|
-
* @param {object} params Job parameters.
|
|
270
|
-
* @param {string} params.id Job ID.
|
|
271
|
-
* @param {Function} [cb] Callback function.
|
|
272
|
-
* @returns {Promise|undefined}
|
|
273
|
-
*/
|
|
274
|
-
errors(params, cb) {
|
|
275
|
-
if (!params.id || typeof params.id !== 'string') {
|
|
276
|
-
throw new ArgumentError('The id parameter must be a valid job id');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
if (cb && cb instanceof Function) {
|
|
280
|
-
return this.jobErrors.get(params, cb);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Return a promise.
|
|
284
|
-
return this.jobErrors.get(params);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Send a verification email to a user.
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* var params = {
|
|
292
|
-
* user_id: '{USER_ID}'
|
|
293
|
-
* };
|
|
294
|
-
*
|
|
295
|
-
* management.jobs.verifyEmail(params, function (err) {
|
|
296
|
-
* if (err) {
|
|
297
|
-
* // Handle error.
|
|
298
|
-
* }
|
|
299
|
-
* });
|
|
300
|
-
* @param {object} data User data object.
|
|
301
|
-
* @param {string} data.user_id ID of the user to be verified.
|
|
302
|
-
* @param {string} [data.organization_id] Organization ID
|
|
303
|
-
* @param {string} [data.client_id] client_id of the client (application). If no value provided, the global Client ID will be used.
|
|
304
|
-
* @param {object} [data.identity] Used to verify secondary, federated, and passwordless-email identities.
|
|
305
|
-
* @param {string} data.identity.user_id user_id of the identity.
|
|
306
|
-
* @param {string} data.identity.provider provider of the identity.
|
|
307
|
-
* @param {Function} [cb] Callback function.
|
|
308
|
-
* @returns {Promise|undefined}
|
|
309
|
-
*/
|
|
310
|
-
verifyEmail(data, cb) {
|
|
311
|
-
if (!data.user_id || typeof data.user_id !== 'string') {
|
|
312
|
-
throw new ArgumentError('Must specify a user ID');
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (cb && cb instanceof Function) {
|
|
316
|
-
return this.jobs.create({ id: 'verification-email' }, data, cb);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Return a promise.
|
|
320
|
-
return this.jobs.create({ id: 'verification-email' }, data);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
module.exports = JobsManager;
|