@stackfactor/client-api 1.0.32 → 1.0.34

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/lib/users.js CHANGED
@@ -1,612 +1,614 @@
1
- import { axios } from "./axiosClient";
1
+ import axios from "./axiosClient";
2
2
  const { removeNullProperties } = require("./utils");
3
3
 
4
- module.exports = {
5
- axios: axios,
6
-
7
- /**
8
- * Add a new API Token
9
- * @param {Date} expiration Expiration date of the token
10
- * @param {String} authToken Authorization token
11
- */
12
- addAPIToken: (name, expiration, authToken) => {
13
- return new Promise(function (resolve, reject) {
14
- const requestData = removeNullProperties({
15
- name: name,
16
- expiration: expiration,
17
- });
18
- const addTokenRequest = axios.post(
19
- `api/v1/users/addapitoken`,
20
- requestData,
21
- {
22
- headers: { authorization: authToken },
23
- }
24
- );
25
- addTokenRequest
26
- .then((result) => {
27
- if (result != null) {
28
- resolve(result.data);
29
- } else {
30
- reject(process.env.ERROR_INVALID_INFORMATION);
31
- }
32
- })
33
- .catch((error) => {
34
- reject(error);
35
- });
36
- });
37
- },
38
-
39
- /**
40
- * Confirm email address
41
- * @param {String} validationCode The code was provided to the user in advance by email
42
- */
43
- confirmEmailAddress: (validationCode) => {
44
- return new Promise(function (resolve, reject) {
45
- const requestData = removeNullProperties({
46
- validationCode: validationCode,
47
- });
48
- const confirmationRequest = axios.post(
49
- "api/v1/users/confirmEmail",
50
- requestData
51
- );
52
- confirmationRequest
53
- .then(() => {
54
- resolve();
55
- })
56
- .catch((error) => {
57
- reject(error);
58
- });
4
+ /**
5
+ * Add a new API Token
6
+ * @param {Date} expiration Expiration date of the token
7
+ * @param {String} authToken Authorization token
8
+ */
9
+ export const addAPIToken = (name, expiration, authToken) => {
10
+ return new Promise(function (resolve, reject) {
11
+ const requestData = removeNullProperties({
12
+ name: name,
13
+ expiration: expiration,
59
14
  });
60
- },
61
-
62
- /**
63
- * Create a new account (tenant). It returns a promise
64
- * @param {String} email User's email address
65
- * @param {String} firstName User's first name
66
- * @param {String} lastName User's last name
67
- * @param {String} password User's password
68
- * @param {String} subSite Subsite where the new account will be created
69
- * @param {String} inviteCode Invitation code received in advance from one of the account owners
70
- * @param
71
- */
72
- createAccount: (
73
- email,
74
- firstName,
75
- lastName,
76
- password,
77
- subSite,
78
- inviteCode
79
- ) => {
80
- return new Promise(function (resolve, reject) {
81
- if (
82
- email.trim() === "" ||
83
- firstName.trim() === "" ||
84
- lastName.trim() === "" ||
85
- password.trim() === "" ||
86
- subSite.trim() === "" ||
87
- inviteCode.trim() === ""
88
- ) {
89
- reject(process.env.ERROR_EMPTY_FIELDS);
90
- } else {
91
- const signupData = removeNullProperties({
92
- email: email,
93
- firstName: firstName,
94
- inviteCode: inviteCode,
95
- lastName: lastName,
96
- password: password,
97
- subSite: subSite,
98
- });
99
- let request = axios.post("api/v1/users/createAccount", signupData);
100
- request
101
- .then((result) => {
102
- resolve(result.data.user);
103
- })
104
- .catch((error) => {
105
- reject(error);
106
- });
107
- }
108
- });
109
- },
110
-
111
- /**
112
- * Create a new user account. It returns a promise
113
- * @param {String} email User's email address
114
- * @param {String} firstName User's first name
115
- * @param {String} lastName User's last name
116
- * @param {String} password User's password
117
- * @param {String} token Invitation token provided to the user
118
- */
119
- createUserAccount: (email, firstName, lastName, password, token) => {
120
- return new Promise(function (resolve, reject) {
121
- if (
122
- email.trim() === "" ||
123
- firstName.trim() === "" ||
124
- lastName.trim() === "" ||
125
- password.trim() === "" ||
126
- token.trim() === ""
127
- ) {
128
- reject(process.env.ERROR_EMPTY_FIELDS);
129
- } else {
130
- const signupData = removeNullProperties({
131
- email: email,
132
- firstName: firstName,
133
- lastName: lastName,
134
- password: password,
135
- token: token,
136
- });
137
- let request = axios.post("api/v1/users/createUser", signupData);
138
- request
139
- .then((result) => {
140
- resolve(result.data.user);
141
- })
142
- .catch((error) => {
143
- reject(error);
144
- });
15
+ const addTokenRequest = axios.post(
16
+ `api/v1/users/addapitoken`,
17
+ requestData,
18
+ {
19
+ headers: { authorization: authToken },
145
20
  }
146
- });
147
- },
148
-
149
- /**
150
- * Delete an existing API token
151
- * @param {String} token Expiration date of the token
152
- * @param {String} authToken Authorization token
153
- */
154
- deleteAPIToken: (token, authToken) => {
155
- return new Promise(function (resolve, reject) {
156
- const deleteTokenRequest = axios.delete(
157
- `api/v1/users/user/token`,
158
- removeNullProperties({
159
- headers: { authorization: authToken },
160
- data: {
161
- token: token,
162
- },
163
- })
164
- );
165
- deleteTokenRequest
166
- .then(() => {
167
- resolve(token);
168
- })
169
- .catch((error) => {
170
- reject(error);
171
- });
172
- });
173
- },
21
+ );
22
+ addTokenRequest
23
+ .then((result) => {
24
+ if (result != null) {
25
+ resolve(result.data);
26
+ } else {
27
+ reject(process.env.ERROR_INVALID_INFORMATION);
28
+ }
29
+ })
30
+ .catch((error) => {
31
+ reject(error);
32
+ });
33
+ });
34
+ };
174
35
 
175
- /**
176
- * Delete existing users
177
- * @param {Array<String>} userIds The ID of the users to be deleted
178
- * @param {String} authToken Authorization token
179
- */
180
- deleteUsers: (userIds, authToken) => {
181
- return new Promise(function (resolve, reject) {
182
- const deleteTokenRequest = axios.delete(
183
- `api/v1/users/`,
184
- removeNullProperties({
185
- headers: { authorization: authToken },
186
- data: {
187
- userIds: userIds,
188
- },
189
- })
190
- );
191
- deleteTokenRequest
192
- .then((response) => {
193
- resolve(response.data);
194
- })
195
- .catch((error) => {
196
- reject(error);
197
- });
36
+ /**
37
+ * Confirm email address
38
+ * @param {String} validationCode The code was provided to the user in advance by email
39
+ */
40
+ export const confirmEmailAddress = (validationCode) => {
41
+ return new Promise(function (resolve, reject) {
42
+ const requestData = removeNullProperties({
43
+ validationCode: validationCode,
198
44
  });
199
- },
45
+ const confirmationRequest = axios.post(
46
+ "api/v1/users/confirmEmail",
47
+ requestData
48
+ );
49
+ confirmationRequest
50
+ .then(() => {
51
+ resolve();
52
+ })
53
+ .catch((error) => {
54
+ reject(error);
55
+ });
56
+ });
57
+ };
200
58
 
201
- /**
202
- * Get all the API tokens
203
- * @param {String} authToken Authorization token
204
- */
205
- getAPITokens: (authToken) => {
206
- return new Promise(function (resolve, reject) {
207
- const getTokensRequest = axios.get(`api/v1/users/getapitokens`, {
208
- headers: { authorization: authToken },
59
+ /**
60
+ * Create a new account (tenant). It returns a promise
61
+ * @param {String} email User's email address
62
+ * @param {String} firstName User's first name
63
+ * @param {String} lastName User's last name
64
+ * @param {String} password User's password
65
+ * @param {String} subSite Subsite where the new account will be created
66
+ * @param {String} inviteCode Invitation code received in advance from one of the account owners
67
+ * @param
68
+ */
69
+ export const createAccount = (
70
+ email,
71
+ firstName,
72
+ lastName,
73
+ password,
74
+ subSite,
75
+ inviteCode
76
+ ) => {
77
+ return new Promise(function (resolve, reject) {
78
+ if (
79
+ email.trim() === "" ||
80
+ firstName.trim() === "" ||
81
+ lastName.trim() === "" ||
82
+ password.trim() === "" ||
83
+ subSite.trim() === "" ||
84
+ inviteCode.trim() === ""
85
+ ) {
86
+ reject(process.env.ERROR_EMPTY_FIELDS);
87
+ } else {
88
+ const signupData = removeNullProperties({
89
+ email: email,
90
+ firstName: firstName,
91
+ inviteCode: inviteCode,
92
+ lastName: lastName,
93
+ password: password,
94
+ subSite: subSite,
209
95
  });
210
- getTokensRequest
96
+ let request = axios.post("api/v1/users/createAccount", signupData);
97
+ request
211
98
  .then((result) => {
212
- resolve(result.data);
99
+ resolve(result.data.user);
213
100
  })
214
101
  .catch((error) => {
215
102
  reject(error);
216
103
  });
217
- });
218
- },
104
+ }
105
+ });
106
+ };
219
107
 
220
- /**
221
- * Get the specified user account by Id. It returns a promise
222
- * @param {String} id Id of the user for which information is being requested
223
- */
224
- getUserById: (id) => {
225
- return new Promise(function (resolve, reject) {
226
- const getUserInformationRequest = axios.get(`api/v1/users/user/${id}`);
227
- getUserInformationRequest
108
+ /**
109
+ * Create a new user account. It returns a promise
110
+ * @param {String} email User's email address
111
+ * @param {String} firstName User's first name
112
+ * @param {String} lastName User's last name
113
+ * @param {String} password User's password
114
+ * @param {String} token Invitation token provided to the user
115
+ */
116
+ export const createUserAccount = (
117
+ email,
118
+ firstName,
119
+ lastName,
120
+ password,
121
+ token
122
+ ) => {
123
+ return new Promise(function (resolve, reject) {
124
+ if (
125
+ email.trim() === "" ||
126
+ firstName.trim() === "" ||
127
+ lastName.trim() === "" ||
128
+ password.trim() === "" ||
129
+ token.trim() === ""
130
+ ) {
131
+ reject(process.env.ERROR_EMPTY_FIELDS);
132
+ } else {
133
+ const signupData = removeNullProperties({
134
+ email: email,
135
+ firstName: firstName,
136
+ lastName: lastName,
137
+ password: password,
138
+ token: token,
139
+ });
140
+ let request = axios.post("api/v1/users/createUser", signupData);
141
+ request
228
142
  .then((result) => {
229
- if (result != null) {
230
- resolve(result.data.user);
231
- } else {
232
- reject(process.env.ERROR_INVALID_INFORMATION);
233
- }
143
+ resolve(result.data.user);
234
144
  })
235
145
  .catch((error) => {
236
146
  reject(error);
237
147
  });
238
- });
239
- },
240
-
241
- /**
242
- * Get user information
243
- * @param {String} userId User Id
244
- * @param {String} category User information category
245
- * @param {String} token Authorization token
246
- */
247
- getUserInformation: (userId, category, token) => {
248
- return new Promise(function (resolve, reject) {
249
- let confirmationRequest = axios.get(
250
- `api/v1/users/user/${userId ? userId : 0}/${category ? category : "*"}`,
251
- {
252
- headers: { authorization: token },
253
- }
254
- );
255
- confirmationRequest
256
- .then((response) => {
257
- resolve(response.data);
258
- })
259
- .catch((error) => {
260
- reject(error);
261
- });
262
- });
263
- },
148
+ }
149
+ });
150
+ };
264
151
 
265
- /**
266
- * Get the list of users
267
- * @param {Object} filter Filter to select the users. Ex: {firstName : "John"}
268
- * @param {Array} fields Fields to be loaded. Ex: ["firstName"]
269
- * @param {String} token Authorization token
270
- */
271
- getUsers: (filter, fields, token) => {
272
- return new Promise(function (resolve, reject) {
273
- const requestData = removeNullProperties({
274
- filter: filter,
275
- fields: fields,
276
- });
277
- let confirmationRequest = axios.post(`api/v1/users/`, requestData, {
278
- headers: { authorization: token },
152
+ /**
153
+ * Delete an existing API token
154
+ * @param {String} token Expiration date of the token
155
+ * @param {String} authToken Authorization token
156
+ */
157
+ export const deleteAPIToken = (token, authToken) => {
158
+ return new Promise(function (resolve, reject) {
159
+ const deleteTokenRequest = axios.delete(
160
+ `api/v1/users/user/token`,
161
+ removeNullProperties({
162
+ headers: { authorization: authToken },
163
+ data: {
164
+ token: token,
165
+ },
166
+ })
167
+ );
168
+ deleteTokenRequest
169
+ .then(() => {
170
+ resolve(token);
171
+ })
172
+ .catch((error) => {
173
+ reject(error);
279
174
  });
280
- confirmationRequest
281
- .then((response) => {
282
- resolve(response.data);
283
- })
284
- .catch((error) => {
285
- reject(error);
286
- });
287
- });
288
- },
175
+ });
176
+ };
289
177
 
290
- /**
291
- * Invite other users to join the same account
292
- * @param {Array<String>} invitees List of emails of the invitees
293
- * @param {String} token Authorization token
294
- */
295
- inviteUsers: (invitees, authToken) => {
296
- return new Promise(function (resolve, reject) {
297
- const requestData = removeNullProperties({
298
- invitees: invitees,
299
- token: authToken,
300
- });
301
- let request = axios.post("api/v1/users/invite", requestData, {
178
+ /**
179
+ * Delete existing users
180
+ * @param {Array<String>} userIds The ID of the users to be deleted
181
+ * @param {String} authToken Authorization token
182
+ */
183
+ export const deleteUsers = (userIds, authToken) => {
184
+ return new Promise(function (resolve, reject) {
185
+ const deleteTokenRequest = axios.delete(
186
+ `api/v1/users/`,
187
+ removeNullProperties({
302
188
  headers: { authorization: authToken },
189
+ data: {
190
+ userIds: userIds,
191
+ },
192
+ })
193
+ );
194
+ deleteTokenRequest
195
+ .then((response) => {
196
+ resolve(response.data);
197
+ })
198
+ .catch((error) => {
199
+ reject(error);
303
200
  });
304
- request
305
- .then((response) => {
306
- resolve(response.data);
307
- })
308
- .catch((error) => {
309
- reject(error);
310
- });
201
+ });
202
+ };
203
+
204
+ /**
205
+ * Get all the API tokens
206
+ * @param {String} authToken Authorization token
207
+ */
208
+ export const getAPITokens = (authToken) => {
209
+ return new Promise(function (resolve, reject) {
210
+ const getTokensRequest = axios.get(`api/v1/users/getapitokens`, {
211
+ headers: { authorization: authToken },
311
212
  });
312
- },
213
+ getTokensRequest
214
+ .then((result) => {
215
+ resolve(result.data);
216
+ })
217
+ .catch((error) => {
218
+ reject(error);
219
+ });
220
+ });
221
+ };
313
222
 
314
- /**
315
- * Login using email and password. It returns a promise
316
- * @param {String} email User's email address
317
- * @param {String} password User's password
318
- * @param {boolean} rememberMe Set to true if the user wants his account to be saved on the current machine
319
- */
320
- login: (email, password, rememberMe) => {
321
- return new Promise(function (resolve, reject) {
322
- const requestData = removeNullProperties({
323
- email: email,
324
- password: password,
325
- rememberMe: rememberMe,
223
+ /**
224
+ * Get the specified user account by Id. It returns a promise
225
+ * @param {String} id Id of the user for which information is being requested
226
+ */
227
+ export const getUserById = (id) => {
228
+ return new Promise(function (resolve, reject) {
229
+ const getUserInformationRequest = axios.get(`api/v1/users/user/${id}`);
230
+ getUserInformationRequest
231
+ .then((result) => {
232
+ if (result != null) {
233
+ resolve(result.data.user);
234
+ } else {
235
+ reject(process.env.ERROR_INVALID_INFORMATION);
236
+ }
237
+ })
238
+ .catch((error) => {
239
+ reject(error);
326
240
  });
327
- let request = axios.post("api/v1/auth/login", requestData);
328
- request
329
- .then((response) => {
330
- resolve(response.data);
331
- })
332
- .catch((error) => {
333
- reject(error);
334
- });
335
- });
336
- },
241
+ });
242
+ };
337
243
 
338
- /**
339
- * Logout from the server. It returns a promise
340
- * @param {String} token Authorization token
341
- */
342
- logout: (token) => {
343
- return new Promise(function (resolve, reject) {
344
- const options = removeNullProperties({
244
+ /**
245
+ * Get user information
246
+ * @param {String} userId User Id
247
+ * @param {String} category User information category
248
+ * @param {String} token Authorization token
249
+ */
250
+ export const getUserInformation = (userId, category, token) => {
251
+ return new Promise(function (resolve, reject) {
252
+ let confirmationRequest = axios.get(
253
+ `api/v1/users/user/${userId ? userId : 0}/${category ? category : "*"}`,
254
+ {
345
255
  headers: { authorization: token },
256
+ }
257
+ );
258
+ confirmationRequest
259
+ .then((response) => {
260
+ resolve(response.data);
261
+ })
262
+ .catch((error) => {
263
+ reject(error);
346
264
  });
347
- let request = axios.post("api/v1/auth/logout", {}, options);
348
- request
349
- .then((response) => {
350
- resolve(response.data);
351
- })
352
- .catch((error) => {
353
- reject(error);
354
- });
265
+ });
266
+ };
267
+
268
+ /**
269
+ * Get the list of users
270
+ * @param {Object} filter Filter to select the users. Ex: {firstName : "John"}
271
+ * @param {Array} fields Fields to be loaded. Ex: ["firstName"]
272
+ * @param {String} token Authorization token
273
+ */
274
+ export const getUsers = (filter, fields, token) => {
275
+ return new Promise(function (resolve, reject) {
276
+ const requestData = removeNullProperties({
277
+ filter: filter,
278
+ fields: fields,
279
+ });
280
+ let confirmationRequest = axios.post(`api/v1/users/`, requestData, {
281
+ headers: { authorization: token },
355
282
  });
356
- },
283
+ confirmationRequest
284
+ .then((response) => {
285
+ resolve(response.data);
286
+ })
287
+ .catch((error) => {
288
+ reject(error);
289
+ });
290
+ });
291
+ };
357
292
 
358
- /**
359
- * Checks the current auth token and maintain it alive. It returns a promise. In case the token is invalid
360
- * a new token can be restablished using login
361
- * @param {String} token User's auth token to be refreshed
362
- */
363
- refreshToken: (token) => {
364
- return new Promise(function (resolve, reject) {
365
- let options = removeNullProperties({ headers: { Authorization: token } });
366
- let request = axios.post("api/v1/auth/refreshToken", {}, options);
367
- request
368
- .then((response) => {
369
- resolve(response.data);
370
- })
371
- .catch((error) => {
372
- reject(error);
373
- });
293
+ /**
294
+ * Invite other users to join the same account
295
+ * @param {Array<String>} invitees List of emails of the invitees
296
+ * @param {String} token Authorization token
297
+ */
298
+ export const inviteUsers = (invitees, authToken) => {
299
+ return new Promise(function (resolve, reject) {
300
+ const requestData = removeNullProperties({
301
+ invitees: invitees,
302
+ token: authToken,
303
+ });
304
+ let request = axios.post("api/v1/users/invite", requestData, {
305
+ headers: { authorization: authToken },
374
306
  });
375
- },
307
+ request
308
+ .then((response) => {
309
+ resolve(response.data);
310
+ })
311
+ .catch((error) => {
312
+ reject(error);
313
+ });
314
+ });
315
+ };
376
316
 
377
- /**
378
- * Remove an existing API token
379
- * @param {String} id The ID of the token to be removed
380
- * @param {String} authToken Authorization token
381
- */
382
- removeAPIToken: (id, authToken) => {
383
- return new Promise(function (resolve, reject) {
384
- const requestData = removeNullProperties({
385
- id: id,
317
+ /**
318
+ * Login using email and password. It returns a promise
319
+ * @param {String} email User's email address
320
+ * @param {String} password User's password
321
+ * @param {boolean} rememberMe Set to true if the user wants his account to be saved on the current machine
322
+ */
323
+ export const login = (email, password, rememberMe) => {
324
+ return new Promise(function (resolve, reject) {
325
+ const requestData = removeNullProperties({
326
+ email: email,
327
+ password: password,
328
+ rememberMe: rememberMe,
329
+ });
330
+ let request = axios.post("api/v1/auth/login", requestData);
331
+ request
332
+ .then((response) => {
333
+ resolve(response.data);
334
+ })
335
+ .catch((error) => {
336
+ reject(error);
386
337
  });
387
- const removeTokenRequest = axios.post(
388
- `api/v1/users/removeapitoken`,
389
- requestData,
390
- {
391
- headers: { authorization: authToken },
392
- }
393
- );
394
- removeTokenRequest
395
- .then(() => {
396
- resolve(id);
397
- })
398
- .catch((error) => {
399
- reject(error);
400
- });
338
+ });
339
+ };
340
+
341
+ /**
342
+ * Logout from the server. It returns a promise
343
+ * @param {String} token Authorization token
344
+ */
345
+ export const logout = (token) => {
346
+ return new Promise(function (resolve, reject) {
347
+ const options = removeNullProperties({
348
+ headers: { authorization: token },
401
349
  });
402
- },
350
+ let request = axios.post("api/v1/auth/logout", {}, options);
351
+ request
352
+ .then((response) => {
353
+ resolve(response.data);
354
+ })
355
+ .catch((error) => {
356
+ reject(error);
357
+ });
358
+ });
359
+ };
403
360
 
404
- /**
405
- * Resend invitation emails
406
- * @param {Array<String>} invitees List of emails of the invitees
407
- * @param {String} token Authorization token
408
- */
409
- resendInvitationEmails: (invitees, authToken) => {
410
- return new Promise(function (resolve, reject) {
411
- const requestData = removeNullProperties({
412
- invitees: invitees,
413
- token: authToken,
361
+ /**
362
+ * Checks the current auth token and maintain it alive. It returns a promise. In case the token is invalid
363
+ * a new token can be restablished using login
364
+ * @param {String} token User's auth token to be refreshed
365
+ */
366
+ export const refreshToken = (token) => {
367
+ return new Promise(function (resolve, reject) {
368
+ let options = removeNullProperties({ headers: { Authorization: token } });
369
+ let request = axios.post("api/v1/auth/refreshToken", {}, options);
370
+ request
371
+ .then((response) => {
372
+ resolve(response.data);
373
+ })
374
+ .catch((error) => {
375
+ reject(error);
414
376
  });
415
- let request = axios.post("api/v1/users/resendinvite", requestData, {
377
+ });
378
+ };
379
+
380
+ /**
381
+ * Remove an existing API token
382
+ * @param {String} id The ID of the token to be removed
383
+ * @param {String} authToken Authorization token
384
+ */
385
+ export const removeAPIToken = (id, authToken) => {
386
+ return new Promise(function (resolve, reject) {
387
+ const requestData = removeNullProperties({
388
+ id: id,
389
+ });
390
+ const removeTokenRequest = axios.post(
391
+ `api/v1/users/removeapitoken`,
392
+ requestData,
393
+ {
416
394
  headers: { authorization: authToken },
395
+ }
396
+ );
397
+ removeTokenRequest
398
+ .then(() => {
399
+ resolve(id);
400
+ })
401
+ .catch((error) => {
402
+ reject(error);
417
403
  });
418
- request
419
- .then((response) => {
420
- resolve(response.data);
421
- })
422
- .catch((error) => {
423
- reject(error);
424
- });
425
- });
426
- },
404
+ });
405
+ };
427
406
 
428
- /**
429
- * Reset the password. It returns a promise
430
- * @param {String} code Code provided to the user by email
431
- * @param {String} email User's email address
432
- * @param {String} password User's new password
433
- */
434
- resetPassword: (email, code, password) => {
435
- return new Promise(function (resolve, reject) {
436
- let postData = removeNullProperties({
437
- email: email,
438
- code: code,
439
- password: password,
440
- });
441
- let request = axios.post("api/v1/users/resetpassword", postData);
442
- request
443
- .then((response) => {
444
- resolve(response.data);
445
- })
446
- .catch((error) => {
447
- reject(error);
448
- });
407
+ /**
408
+ * Resend invitation emails
409
+ * @param {Array<String>} invitees List of emails of the invitees
410
+ * @param {String} token Authorization token
411
+ */
412
+ export const resendInvitationEmails = (invitees, authToken) => {
413
+ return new Promise(function (resolve, reject) {
414
+ const requestData = removeNullProperties({
415
+ invitees: invitees,
416
+ token: authToken,
417
+ });
418
+ let request = axios.post("api/v1/users/resendinvite", requestData, {
419
+ headers: { authorization: authToken },
449
420
  });
450
- },
421
+ request
422
+ .then((response) => {
423
+ resolve(response.data);
424
+ })
425
+ .catch((error) => {
426
+ reject(error);
427
+ });
428
+ });
429
+ };
451
430
 
452
- /**
453
- * Send an email to the user indicated by the email address to reset the password. It returns a promise
454
- * @param {String} email Email of the user who needs to reset the password
455
- */
456
- sendPasswordResetNotification: (email) => {
457
- return new Promise(function (resolve, reject) {
458
- let postData = removeNullProperties({
459
- email: email,
431
+ /**
432
+ * Reset the password. It returns a promise
433
+ * @param {String} code Code provided to the user by email
434
+ * @param {String} email User's email address
435
+ * @param {String} password User's new password
436
+ */
437
+ export const resetPassword = (email, code, password) => {
438
+ return new Promise(function (resolve, reject) {
439
+ let postData = removeNullProperties({
440
+ email: email,
441
+ code: code,
442
+ password: password,
443
+ });
444
+ let request = axios.post("api/v1/users/resetpassword", postData);
445
+ request
446
+ .then((response) => {
447
+ resolve(response.data);
448
+ })
449
+ .catch((error) => {
450
+ reject(error);
460
451
  });
461
- let request = axios.post(
462
- "api/v1/users/sendpasswordresetnotification",
463
- postData
464
- );
465
- request
466
- .then((response) => {
467
- resolve(response.data);
468
- })
469
- .catch((error) => {
470
- reject(error);
471
- });
452
+ });
453
+ };
454
+
455
+ /**
456
+ * Send an email to the user indicated by the email address to reset the password. It returns a promise
457
+ * @param {String} email Email of the user who needs to reset the password
458
+ */
459
+ export const sendPasswordResetNotification = (email) => {
460
+ return new Promise(function (resolve, reject) {
461
+ let postData = removeNullProperties({
462
+ email: email,
472
463
  });
473
- },
464
+ let request = axios.post(
465
+ "api/v1/users/sendpasswordresetnotification",
466
+ postData
467
+ );
468
+ request
469
+ .then((response) => {
470
+ resolve(response.data);
471
+ })
472
+ .catch((error) => {
473
+ reject(error);
474
+ });
475
+ });
476
+ };
474
477
 
475
- /**
476
- * Set user profile information
477
- * @param {String} userId User Id
478
- * @param {String} category User information category
479
- * @param {String} data New or updated user data information
480
- * @param {Object} token Authorization token
481
- */
482
- setUserInformation: (userId, category, data, token) => {
483
- return new Promise(function (resolve, reject) {
484
- const requestData = removeNullProperties({
485
- data: category ? { category: { ...data } } : data,
486
- userId: userId,
478
+ /**
479
+ * Set user profile information
480
+ * @param {String} userId User Id
481
+ * @param {String} category User information category
482
+ * @param {String} data New or updated user data information
483
+ * @param {Object} token Authorization token
484
+ */
485
+ export const setUserInformation = (userId, category, data, token) => {
486
+ return new Promise(function (resolve, reject) {
487
+ const requestData = removeNullProperties({
488
+ data: category ? { category: { ...data } } : data,
489
+ userId: userId,
490
+ });
491
+ let confirmationRequest = axios.post("api/v1/users/user", requestData, {
492
+ headers: { authorization: token },
493
+ });
494
+ confirmationRequest
495
+ .then((response) => {
496
+ resolve(response.data);
497
+ })
498
+ .catch((error) => {
499
+ reject(error);
487
500
  });
488
- let confirmationRequest = axios.post("api/v1/users/user", requestData, {
501
+ });
502
+ };
503
+
504
+ /**
505
+ * Update user email
506
+ * @param {String} email The new email address
507
+ * @param {String} password The current password
508
+ * @param {String} token Authorization token
509
+ */
510
+ export const updateUserEmail = (email, password, token) => {
511
+ return new Promise(function (resolve, reject) {
512
+ const requestData = removeNullProperties({
513
+ email: email,
514
+ password: password,
515
+ });
516
+ let confirmationRequest = axios.post(
517
+ "api/v1/users/updateemail",
518
+ requestData,
519
+ {
489
520
  headers: { authorization: token },
521
+ }
522
+ );
523
+ confirmationRequest
524
+ .then((response) => {
525
+ resolve(response.data);
526
+ })
527
+ .catch((error) => {
528
+ reject(error);
490
529
  });
491
- confirmationRequest
492
- .then((response) => {
493
- resolve(response.data);
494
- })
495
- .catch((error) => {
496
- reject(error);
497
- });
498
- });
499
- },
530
+ });
531
+ };
500
532
 
501
- /**
502
- * Update user email
503
- * @param {String} email The new email address
504
- * @param {String} password The current password
505
- * @param {String} token Authorization token
506
- */
507
- updateUserEmail: (email, password, token) => {
508
- return new Promise(function (resolve, reject) {
509
- const requestData = removeNullProperties({
510
- email: email,
511
- password: password,
512
- });
513
- let confirmationRequest = axios.post(
514
- "api/v1/users/updateemail",
515
- requestData,
516
- {
517
- headers: { authorization: token },
518
- }
519
- );
520
- confirmationRequest
521
- .then((response) => {
522
- resolve(response.data);
523
- })
524
- .catch((error) => {
525
- reject(error);
526
- });
533
+ /**
534
+ * Update user groups
535
+ * @param {String} userIds The id of the user
536
+ * @param {Array<String>} groups The id of the groups the user should belong to
537
+ * @param {String} token Authorization token
538
+ */
539
+ export const updateUserGroups = (userId, groups, token) => {
540
+ return new Promise(function (resolve, reject) {
541
+ const requestData = removeNullProperties({
542
+ userId: userId,
543
+ groups: groups ? groups : [],
527
544
  });
528
- },
529
-
530
- /**
531
- * Update user groups
532
- * @param {String} userIds The id of the user
533
- * @param {Array<String>} groups The id of the groups the user should belong to
534
- * @param {String} token Authorization token
535
- */
536
- updateUserGroups: (userId, groups, token) => {
537
- return new Promise(function (resolve, reject) {
538
- const requestData = removeNullProperties({
539
- userId: userId,
540
- groups: groups ? groups : [],
545
+ let confirmationRequest = axios.post(
546
+ "api/v1/users/user/updategroups",
547
+ requestData,
548
+ {
549
+ headers: { authorization: token },
550
+ }
551
+ );
552
+ confirmationRequest
553
+ .then(() => {
554
+ resolve(requestData);
555
+ })
556
+ .catch((error) => {
557
+ reject(error);
541
558
  });
542
- let confirmationRequest = axios.post(
543
- "api/v1/users/user/updategroups",
544
- requestData,
545
- {
546
- headers: { authorization: token },
547
- }
548
- );
549
- confirmationRequest
550
- .then(() => {
551
- resolve(requestData);
552
- })
553
- .catch((error) => {
554
- reject(error);
555
- });
556
- });
557
- },
559
+ });
560
+ };
558
561
 
559
- /**
560
- * Update user password
561
- * @param {String} password The current password
562
- * @param {String} newPassword The new password
563
- * @param {String} token Authorization token
564
- */
565
- updateUserPassword: (password, newPassword, token) => {
566
- return new Promise(function (resolve, reject) {
567
- const requestData = removeNullProperties({
568
- password: password,
569
- newPassword: newPassword,
570
- });
571
- let confirmationRequest = axios.post(
572
- "api/v1/users/updatepassword",
573
- requestData,
574
- {
575
- headers: { authorization: token },
576
- }
577
- );
578
- confirmationRequest
579
- .then((response) => {
580
- resolve(response.data);
581
- })
582
- .catch((error) => {
583
- reject(error);
584
- });
562
+ /**
563
+ * Update user password
564
+ * @param {String} password The current password
565
+ * @param {String} newPassword The new password
566
+ * @param {String} token Authorization token
567
+ */
568
+ export const updateUserPassword = (password, newPassword, token) => {
569
+ return new Promise(function (resolve, reject) {
570
+ const requestData = removeNullProperties({
571
+ password: password,
572
+ newPassword: newPassword,
585
573
  });
586
- },
587
-
588
- /**
589
- * Validate reset password code. It returns a promise
590
- * @param {String} email User's email address
591
- * @param {String} code Provided reset code
592
- */
593
- validateResetPasswordCode: (email, code) => {
594
- return new Promise(function (resolve, reject) {
595
- let postData = removeNullProperties({
596
- email: email,
597
- code: code,
574
+ let confirmationRequest = axios.post(
575
+ "api/v1/users/updatepassword",
576
+ requestData,
577
+ {
578
+ headers: { authorization: token },
579
+ }
580
+ );
581
+ confirmationRequest
582
+ .then((response) => {
583
+ resolve(response.data);
584
+ })
585
+ .catch((error) => {
586
+ reject(error);
598
587
  });
599
- let request = axios.post(
600
- "api/v1/users/validateresetpasswordcode",
601
- postData
602
- );
603
- request
604
- .then((response) => {
605
- resolve(response.data);
606
- })
607
- .catch((error) => {
608
- reject(error);
609
- });
588
+ });
589
+ };
590
+
591
+ /**
592
+ * Validate reset password code. It returns a promise
593
+ * @param {String} email User's email address
594
+ * @param {String} code Provided reset code
595
+ */
596
+ export const validateResetPasswordCode = (email, code) => {
597
+ return new Promise(function (resolve, reject) {
598
+ let postData = removeNullProperties({
599
+ email: email,
600
+ code: code,
610
601
  });
611
- },
602
+ let request = axios.post(
603
+ "api/v1/users/validateresetpasswordcode",
604
+ postData
605
+ );
606
+ request
607
+ .then((response) => {
608
+ resolve(response.data);
609
+ })
610
+ .catch((error) => {
611
+ reject(error);
612
+ });
613
+ });
612
614
  };