@stackfactor/client-api 1.1.12-9.1 → 1.1.12
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/{exports.ts → exports.js} +0 -14
- package/index.js +3 -0
- package/lib/{actionNotifications.ts → actionNotifications.js} +11 -21
- package/lib/{address.ts → address.js} +5 -4
- package/lib/axiosClient.js +85 -0
- package/lib/{config.ts → config.js} +9 -20
- package/lib/{constants.ts → constants.js} +41 -11
- package/lib/{dashboard.ts → dashboard.js} +10 -19
- package/lib/{departmentTrainingPlans.ts → departmentTrainingPlans.js} +32 -63
- package/lib/{groups.ts → groups.js} +29 -68
- package/lib/{integration.ts → integration.js} +47 -103
- package/lib/{integrationConfiguration.ts → integrationConfiguration.js} +22 -27
- package/lib/integrations/{contentGenerator.ts → contentGenerator.js} +18 -38
- package/lib/{learningContent.ts → learningContent.js} +62 -218
- package/lib/{learningPath.ts → learningPath.js} +30 -57
- package/lib/{logger.ts → logger.js} +8 -18
- package/lib/{role.ts → role.js} +69 -117
- package/lib/{roleTemplate.ts → roleTemplate.js} +30 -65
- package/lib/{skill.ts → skill.js} +87 -125
- package/lib/skillAssessmentTestingSession.js +148 -0
- package/lib/{skillAssessments.ts → skillAssessments.js} +16 -63
- package/lib/{skillTemplate.ts → skillTemplate.js} +42 -73
- package/lib/{teams.ts → teams.js} +38 -73
- package/lib/{tenants.ts → tenants.js} +10 -17
- package/lib/{trainingPlans.ts → trainingPlans.js} +56 -159
- package/lib/{userInformation.ts → userInformation.js} +26 -27
- package/lib/{users.ts → users.js} +140 -239
- package/lib/utils.js +48 -0
- package/package.json +1 -12
- package/.eslintrc.json +0 -13
- package/index.ts +0 -1
- package/lib/aiAssistant.ts +0 -197
- package/lib/avatar.ts +0 -41
- package/lib/axiosClient.ts +0 -92
- package/lib/microSkillsQuizes.ts +0 -70
- package/lib/quotas.ts +0 -59
- package/lib/security.ts +0 -99
- package/lib/skillAssessmentTestingSession.ts +0 -192
- package/lib/talentTransfromation.ts +0 -126
- package/lib/trainingPlansProficiencyLevels.ts +0 -132
- package/lib/utils.ts +0 -64
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
1
|
import { client } from "./axiosClient.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Add a new API Token
|
|
6
|
-
* @param {string} name Name of the token
|
|
7
5
|
* @param {Date} expiration Expiration date of the token
|
|
8
|
-
* @param {
|
|
9
|
-
* @returns {Promise<object>}
|
|
6
|
+
* @param {String} authToken Authorization token
|
|
10
7
|
*/
|
|
11
|
-
const addAPIToken = (name
|
|
12
|
-
return new Promise((resolve, reject)
|
|
8
|
+
export const addAPIToken = (name, expiration, authToken) => {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
13
10
|
const requestData = {
|
|
14
11
|
name: name,
|
|
15
12
|
expiration: expiration,
|
|
@@ -18,7 +15,7 @@ const addAPIToken = (name: string, expiration: Date, token: string): Promise<obj
|
|
|
18
15
|
`api/v1/users/addapitoken`,
|
|
19
16
|
requestData,
|
|
20
17
|
{
|
|
21
|
-
headers: { authorization:
|
|
18
|
+
headers: { authorization: authToken },
|
|
22
19
|
}
|
|
23
20
|
);
|
|
24
21
|
addTokenRequest
|
|
@@ -37,11 +34,10 @@ const addAPIToken = (name: string, expiration: Date, token: string): Promise<obj
|
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* Confirm email address
|
|
40
|
-
* @param {
|
|
41
|
-
* @returns {Promise<void>}
|
|
37
|
+
* @param {String} validationCode The code was provided to the user in advance by email
|
|
42
38
|
*/
|
|
43
|
-
const confirmEmailAddress = (validationCode
|
|
44
|
-
return new Promise((resolve, reject)
|
|
39
|
+
export const confirmEmailAddress = (validationCode) => {
|
|
40
|
+
return new Promise(function (resolve, reject) {
|
|
45
41
|
const requestData = {
|
|
46
42
|
validationCode: validationCode,
|
|
47
43
|
};
|
|
@@ -61,12 +57,11 @@ const confirmEmailAddress = (validationCode: string): Promise<void> => {
|
|
|
61
57
|
|
|
62
58
|
/**
|
|
63
59
|
* Confirm phone number
|
|
64
|
-
* @param {
|
|
65
|
-
* @param {
|
|
66
|
-
* @returns {Promise<object>}
|
|
60
|
+
* @param {String} validationCode The code was provided to the user in advance by email
|
|
61
|
+
* @param {String} authToken Authorization token
|
|
67
62
|
*/
|
|
68
|
-
const confirmPhone = (validationCode
|
|
69
|
-
return new Promise((resolve, reject)
|
|
63
|
+
export const confirmPhone = (validationCode, authToken) => {
|
|
64
|
+
return new Promise(function (resolve, reject) {
|
|
70
65
|
const requestData = {
|
|
71
66
|
validationCode: validationCode,
|
|
72
67
|
};
|
|
@@ -74,7 +69,7 @@ const confirmPhone = (validationCode: string, token: string): Promise<object> =>
|
|
|
74
69
|
"api/v1/users/confirmPhone",
|
|
75
70
|
requestData,
|
|
76
71
|
{
|
|
77
|
-
headers: { authorization:
|
|
72
|
+
headers: { authorization: authToken },
|
|
78
73
|
}
|
|
79
74
|
);
|
|
80
75
|
confirmationRequest
|
|
@@ -89,12 +84,11 @@ const confirmPhone = (validationCode: string, token: string): Promise<object> =>
|
|
|
89
84
|
|
|
90
85
|
/**
|
|
91
86
|
* Generate confirmation code
|
|
92
|
-
* @param {
|
|
93
|
-
* @param {
|
|
94
|
-
* @returns {Promise<object>}
|
|
87
|
+
* @param {String} phoneNumber Send confirmation code to the phone number
|
|
88
|
+
* @param {String} authToken Authorization token
|
|
95
89
|
*/
|
|
96
|
-
const confirmPhoneGenerateCode = (phoneNumber
|
|
97
|
-
return new Promise((resolve, reject)
|
|
90
|
+
export const confirmPhoneGenerateCode = (phoneNumber, authToken) => {
|
|
91
|
+
return new Promise(function (resolve, reject) {
|
|
98
92
|
const requestData = {
|
|
99
93
|
phoneNumber: phoneNumber,
|
|
100
94
|
};
|
|
@@ -102,7 +96,7 @@ const confirmPhoneGenerateCode = (phoneNumber: string, token: string): Promise<o
|
|
|
102
96
|
"api/v1/users/confirmPhoneGenerateCode",
|
|
103
97
|
requestData,
|
|
104
98
|
{
|
|
105
|
-
headers: { authorization:
|
|
99
|
+
headers: { authorization: authToken },
|
|
106
100
|
}
|
|
107
101
|
);
|
|
108
102
|
confirmationRequest
|
|
@@ -117,23 +111,23 @@ const confirmPhoneGenerateCode = (phoneNumber: string, token: string): Promise<o
|
|
|
117
111
|
|
|
118
112
|
/**
|
|
119
113
|
* Create a new account (tenant). It returns a promise
|
|
120
|
-
* @param {
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {
|
|
123
|
-
* @param {
|
|
124
|
-
* @param {
|
|
125
|
-
* @param {
|
|
126
|
-
* @
|
|
114
|
+
* @param {String} email User's email address
|
|
115
|
+
* @param {String} firstName User's first name
|
|
116
|
+
* @param {String} lastName User's last name
|
|
117
|
+
* @param {String} password User's password
|
|
118
|
+
* @param {String} subSite Subsite where the new account will be created
|
|
119
|
+
* @param {String} inviteCode Invitation code received in advance from one of the account owners
|
|
120
|
+
* @param
|
|
127
121
|
*/
|
|
128
|
-
const createAccount = (
|
|
129
|
-
email
|
|
130
|
-
firstName
|
|
131
|
-
lastName
|
|
132
|
-
password
|
|
133
|
-
subSite
|
|
134
|
-
inviteCode
|
|
135
|
-
)
|
|
136
|
-
return new Promise((resolve, reject)
|
|
122
|
+
export const createAccount = (
|
|
123
|
+
email,
|
|
124
|
+
firstName,
|
|
125
|
+
lastName,
|
|
126
|
+
password,
|
|
127
|
+
subSite,
|
|
128
|
+
inviteCode
|
|
129
|
+
) => {
|
|
130
|
+
return new Promise(function (resolve, reject) {
|
|
137
131
|
if (
|
|
138
132
|
email.trim() === "" ||
|
|
139
133
|
firstName.trim() === "" ||
|
|
@@ -166,21 +160,20 @@ const createAccount = (
|
|
|
166
160
|
|
|
167
161
|
/**
|
|
168
162
|
* Create a new user account. It returns a promise
|
|
169
|
-
* @param {
|
|
170
|
-
* @param {
|
|
171
|
-
* @param {
|
|
172
|
-
* @param {
|
|
173
|
-
* @param {
|
|
174
|
-
* @returns {Promise<object>}
|
|
163
|
+
* @param {String} email User's email address
|
|
164
|
+
* @param {String} firstName User's first name
|
|
165
|
+
* @param {String} lastName User's last name
|
|
166
|
+
* @param {String} password User's password
|
|
167
|
+
* @param {String} token Invitation token provided to the user
|
|
175
168
|
*/
|
|
176
|
-
const createUserAccount = (
|
|
177
|
-
email
|
|
178
|
-
firstName
|
|
179
|
-
lastName
|
|
180
|
-
password
|
|
181
|
-
token
|
|
182
|
-
)
|
|
183
|
-
return new Promise((resolve, reject)
|
|
169
|
+
export const createUserAccount = (
|
|
170
|
+
email,
|
|
171
|
+
firstName,
|
|
172
|
+
lastName,
|
|
173
|
+
password,
|
|
174
|
+
token
|
|
175
|
+
) => {
|
|
176
|
+
return new Promise(function (resolve, reject) {
|
|
184
177
|
if (
|
|
185
178
|
email.trim() === "" ||
|
|
186
179
|
firstName.trim() === "" ||
|
|
@@ -211,12 +204,11 @@ const createUserAccount = (
|
|
|
211
204
|
|
|
212
205
|
/**
|
|
213
206
|
* Delete an existing API token
|
|
214
|
-
* @param {
|
|
215
|
-
* @param {
|
|
216
|
-
* @returns {Promise<string>}
|
|
207
|
+
* @param {String} token Expiration date of the token
|
|
208
|
+
* @param {String} authToken Authorization token
|
|
217
209
|
*/
|
|
218
|
-
const deleteAPIToken = (token
|
|
219
|
-
return new Promise((resolve, reject)
|
|
210
|
+
export const deleteAPIToken = (token, authToken) => {
|
|
211
|
+
return new Promise(function (resolve, reject) {
|
|
220
212
|
const deleteTokenRequest = client.delete(`api/v1/users/user/token`, {
|
|
221
213
|
headers: { authorization: authToken },
|
|
222
214
|
data: {
|
|
@@ -235,14 +227,13 @@ const deleteAPIToken = (token: string, authToken: string): Promise<string> => {
|
|
|
235
227
|
|
|
236
228
|
/**
|
|
237
229
|
* Delete existing users
|
|
238
|
-
* @param {
|
|
239
|
-
* @param {
|
|
240
|
-
* @returns {Promise<object>}
|
|
230
|
+
* @param {Array<String>} userIds The ID of the users to be deleted
|
|
231
|
+
* @param {String} authToken Authorization token
|
|
241
232
|
*/
|
|
242
|
-
const deleteUsers = (userIds
|
|
243
|
-
return new Promise((resolve, reject)
|
|
233
|
+
export const deleteUsers = (userIds, authToken) => {
|
|
234
|
+
return new Promise(function (resolve, reject) {
|
|
244
235
|
const deleteTokenRequest = client.delete(`api/v1/users/`, {
|
|
245
|
-
headers: { authorization:
|
|
236
|
+
headers: { authorization: authToken },
|
|
246
237
|
data: {
|
|
247
238
|
userIds: userIds,
|
|
248
239
|
},
|
|
@@ -259,13 +250,12 @@ const deleteUsers = (userIds: string[], token: string): Promise<object> => {
|
|
|
259
250
|
|
|
260
251
|
/**
|
|
261
252
|
* Get all the API tokens
|
|
262
|
-
* @param {
|
|
263
|
-
* @returns {Promise<object>}
|
|
253
|
+
* @param {String} authToken Authorization token
|
|
264
254
|
*/
|
|
265
|
-
const getAPITokens = (
|
|
266
|
-
return new Promise((resolve, reject)
|
|
255
|
+
export const getAPITokens = (authToken) => {
|
|
256
|
+
return new Promise(function (resolve, reject) {
|
|
267
257
|
const getTokensRequest = client.get(`api/v1/users/getapitokens`, {
|
|
268
|
-
headers: { authorization:
|
|
258
|
+
headers: { authorization: authToken },
|
|
269
259
|
});
|
|
270
260
|
getTokensRequest
|
|
271
261
|
.then((result) => {
|
|
@@ -279,15 +269,11 @@ const getAPITokens = (token: string): Promise<object> => {
|
|
|
279
269
|
|
|
280
270
|
/**
|
|
281
271
|
* Get the specified user account by Id. It returns a promise
|
|
282
|
-
* @param {
|
|
283
|
-
* @param {string} token Authorization token
|
|
284
|
-
* @returns {Promise<object>}
|
|
272
|
+
* @param {String} id Id of the user for which information is being requested
|
|
285
273
|
*/
|
|
286
|
-
const getUserById = (id
|
|
287
|
-
return new Promise((resolve, reject)
|
|
288
|
-
const getUserInformationRequest = client.get(`api/v1/users/user/${id}
|
|
289
|
-
headers: { authorization: token },
|
|
290
|
-
});
|
|
274
|
+
export const getUserById = (id) => {
|
|
275
|
+
return new Promise(function (resolve, reject) {
|
|
276
|
+
const getUserInformationRequest = client.get(`api/v1/users/user/${id}`);
|
|
291
277
|
getUserInformationRequest
|
|
292
278
|
.then((result) => {
|
|
293
279
|
if (result != null) {
|
|
@@ -304,15 +290,14 @@ const getUserById = (id: string, token: string): Promise<object> => {
|
|
|
304
290
|
|
|
305
291
|
/**
|
|
306
292
|
* Get user information
|
|
307
|
-
* @param {
|
|
308
|
-
* @param {
|
|
309
|
-
* @param {
|
|
310
|
-
* @returns {Promise<object>}
|
|
293
|
+
* @param {String} userId User Id
|
|
294
|
+
* @param {String} category User information category
|
|
295
|
+
* @param {String} token Authorization token
|
|
311
296
|
*/
|
|
312
|
-
const getUserInformation = (userId
|
|
313
|
-
return new Promise((resolve, reject)
|
|
297
|
+
export const getUserInformation = (userId, category, token) => {
|
|
298
|
+
return new Promise(function (resolve, reject) {
|
|
314
299
|
let confirmationRequest = client.get(
|
|
315
|
-
`api/v1/users/user/${userId
|
|
300
|
+
`api/v1/users/user/${userId ? userId : 0}/${category ? category : "*"}`,
|
|
316
301
|
{
|
|
317
302
|
headers: { authorization: token },
|
|
318
303
|
}
|
|
@@ -329,13 +314,12 @@ const getUserInformation = (userId: string, category: string, token: string): Pr
|
|
|
329
314
|
|
|
330
315
|
/**
|
|
331
316
|
* Get the list of users
|
|
332
|
-
* @param {
|
|
333
|
-
* @param {
|
|
334
|
-
* @param {
|
|
335
|
-
* @returns {Promise<object>}
|
|
317
|
+
* @param {Object} filter Filter to select the users. Ex: {firstName : "John"}
|
|
318
|
+
* @param {Array} fields Fields to be loaded. Ex: ["firstName"]
|
|
319
|
+
* @param {String} token Authorization token
|
|
336
320
|
*/
|
|
337
|
-
const getUsers = (filter
|
|
338
|
-
return new Promise((resolve, reject)
|
|
321
|
+
export const getUsers = (filter, fields, token) => {
|
|
322
|
+
return new Promise(function (resolve, reject) {
|
|
339
323
|
const requestData = {
|
|
340
324
|
filter: filter,
|
|
341
325
|
fields: fields,
|
|
@@ -355,14 +339,13 @@ const getUsers = (filter: object, fields: string[], token: string): Promise<obje
|
|
|
355
339
|
|
|
356
340
|
/**
|
|
357
341
|
* Invite other users to join the same account
|
|
358
|
-
* @param {
|
|
359
|
-
* @param {
|
|
360
|
-
* @param {
|
|
361
|
-
* @param {
|
|
362
|
-
* @returns {Promise<object>}
|
|
342
|
+
* @param {Array<String>} invitees List of emails of the invitees
|
|
343
|
+
* @param {String} groupId The group the user should be added to
|
|
344
|
+
* @param {String} teamId The team the user should be added to
|
|
345
|
+
* @param {String} token Authorization token
|
|
363
346
|
*/
|
|
364
|
-
const inviteUsers = (invitees
|
|
365
|
-
return new Promise((resolve, reject)
|
|
347
|
+
export const inviteUsers = (invitees, groupId, teamId, authToken) => {
|
|
348
|
+
return new Promise(function (resolve, reject) {
|
|
366
349
|
const requestData = {
|
|
367
350
|
invitees: invitees,
|
|
368
351
|
groupId: groupId,
|
|
@@ -384,15 +367,16 @@ const inviteUsers = (invitees: string[], groupId: string, teamId: string, authTo
|
|
|
384
367
|
|
|
385
368
|
/**
|
|
386
369
|
* Login using email and password. It returns a promise
|
|
387
|
-
* @param {
|
|
388
|
-
* @param {
|
|
389
|
-
* @
|
|
370
|
+
* @param {String} email User's email address
|
|
371
|
+
* @param {String} password User's password
|
|
372
|
+
* @param {boolean} rememberMe Set to true if the user wants his account to be saved on the current machine
|
|
390
373
|
*/
|
|
391
|
-
const login = (email
|
|
392
|
-
return new Promise((resolve, reject)
|
|
374
|
+
export const login = (email, password, rememberMe) => {
|
|
375
|
+
return new Promise(function (resolve, reject) {
|
|
393
376
|
const requestData = {
|
|
394
377
|
email: email,
|
|
395
378
|
password: password,
|
|
379
|
+
rememberMe: rememberMe,
|
|
396
380
|
};
|
|
397
381
|
let request = client.post("api/v1/auth/login", requestData);
|
|
398
382
|
request
|
|
@@ -405,45 +389,16 @@ const login = (email: string, password: string): Promise<object> => {
|
|
|
405
389
|
});
|
|
406
390
|
};
|
|
407
391
|
|
|
408
|
-
/**
|
|
409
|
-
* Login callback after authentication to exchange the code token for authentication and refresh tokens
|
|
410
|
-
* @param {string} code
|
|
411
|
-
* @param {string} codeVerifier
|
|
412
|
-
* @param {string} redirectUri
|
|
413
|
-
* @returns {Promise<object>}
|
|
414
|
-
*/
|
|
415
|
-
const loginExchangeKeys = (code: string, codeVerifier: string, redirectUri: string): Promise<object> => {
|
|
416
|
-
return new Promise((resolve, reject) => {
|
|
417
|
-
const requestData = {
|
|
418
|
-
code: code,
|
|
419
|
-
codeVerifier: codeVerifier,
|
|
420
|
-
redirectUri: redirectUri,
|
|
421
|
-
};
|
|
422
|
-
let request = client.post("api/v1/auth/loginexchangekeys", requestData);
|
|
423
|
-
request
|
|
424
|
-
.then((response) => {
|
|
425
|
-
resolve(response.data);
|
|
426
|
-
})
|
|
427
|
-
.catch((error) => {
|
|
428
|
-
reject(error);
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
};
|
|
432
|
-
|
|
433
392
|
/**
|
|
434
393
|
* Logout from the server. It returns a promise
|
|
435
|
-
* @param {
|
|
436
|
-
* @returns {Promise<object>}
|
|
394
|
+
* @param {String} token Authorization token
|
|
437
395
|
*/
|
|
438
|
-
const logout = (token
|
|
439
|
-
return new Promise((resolve, reject)
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
headers: { authorization: token },
|
|
445
|
-
}
|
|
446
|
-
);
|
|
396
|
+
export const logout = (token) => {
|
|
397
|
+
return new Promise(function (resolve, reject) {
|
|
398
|
+
const options = {
|
|
399
|
+
headers: { authorization: token },
|
|
400
|
+
};
|
|
401
|
+
let request = client.post("api/v1/auth/logout", {}, options);
|
|
447
402
|
request
|
|
448
403
|
.then((response) => {
|
|
449
404
|
resolve(response.data);
|
|
@@ -457,14 +412,12 @@ const logout = (token: string): Promise<object> => {
|
|
|
457
412
|
/**
|
|
458
413
|
* Checks the current auth token and maintain it alive. It returns a promise. In case the token is invalid
|
|
459
414
|
* a new token can be restablished using login
|
|
460
|
-
* @param {
|
|
461
|
-
* @returns {Promise<object>}
|
|
415
|
+
* @param {String} token User's auth token to be refreshed
|
|
462
416
|
*/
|
|
463
|
-
const refreshToken = (
|
|
464
|
-
return new Promise((resolve, reject)
|
|
465
|
-
let
|
|
466
|
-
|
|
467
|
-
});
|
|
417
|
+
export const refreshToken = (token) => {
|
|
418
|
+
return new Promise(function (resolve, reject) {
|
|
419
|
+
let options = { headers: { Authorization: token } };
|
|
420
|
+
let request = client.post("api/v1/auth/refreshToken", {}, options);
|
|
468
421
|
request
|
|
469
422
|
.then((response) => {
|
|
470
423
|
resolve(response.data);
|
|
@@ -477,12 +430,11 @@ const refreshToken = (refreshToken: string): Promise<object> => {
|
|
|
477
430
|
|
|
478
431
|
/**
|
|
479
432
|
* Remove an existing API token
|
|
480
|
-
* @param {
|
|
481
|
-
* @param {
|
|
482
|
-
* @returns {Promise<string>}
|
|
433
|
+
* @param {String} id The ID of the token to be removed
|
|
434
|
+
* @param {String} authToken Authorization token
|
|
483
435
|
*/
|
|
484
|
-
const removeAPIToken = (id
|
|
485
|
-
return new Promise((resolve, reject)
|
|
436
|
+
export const removeAPIToken = (id, authToken) => {
|
|
437
|
+
return new Promise(function (resolve, reject) {
|
|
486
438
|
const requestData = {
|
|
487
439
|
id: id,
|
|
488
440
|
};
|
|
@@ -505,12 +457,11 @@ const removeAPIToken = (id: string, authToken: string): Promise<string> => {
|
|
|
505
457
|
|
|
506
458
|
/**
|
|
507
459
|
* Resend invitation emails
|
|
508
|
-
* @param {
|
|
509
|
-
* @param {
|
|
510
|
-
* @returns {Promise<object>}
|
|
460
|
+
* @param {Array<String>} invitees List of emails of the invitees
|
|
461
|
+
* @param {String} token Authorization token
|
|
511
462
|
*/
|
|
512
|
-
const resendInvitationEmails = (invitees
|
|
513
|
-
return new Promise((resolve, reject)
|
|
463
|
+
export const resendInvitationEmails = (invitees, authToken) => {
|
|
464
|
+
return new Promise(function (resolve, reject) {
|
|
514
465
|
const requestData = {
|
|
515
466
|
invitees: invitees,
|
|
516
467
|
token: authToken,
|
|
@@ -530,13 +481,12 @@ const resendInvitationEmails = (invitees: string[], authToken: string): Promise<
|
|
|
530
481
|
|
|
531
482
|
/**
|
|
532
483
|
* Reset the password. It returns a promise
|
|
533
|
-
* @param {
|
|
534
|
-
* @param {
|
|
535
|
-
* @param {
|
|
536
|
-
* @returns {Promise<object>}
|
|
484
|
+
* @param {String} code Code provided to the user by email
|
|
485
|
+
* @param {String} email User's email address
|
|
486
|
+
* @param {String} password User's new password
|
|
537
487
|
*/
|
|
538
|
-
const resetPassword = (email
|
|
539
|
-
return new Promise((resolve, reject)
|
|
488
|
+
export const resetPassword = (email, code, password) => {
|
|
489
|
+
return new Promise(function (resolve, reject) {
|
|
540
490
|
let postData = {
|
|
541
491
|
email: email,
|
|
542
492
|
code: code,
|
|
@@ -553,41 +503,12 @@ const resetPassword = (email: string, code: string, password: string): Promise<o
|
|
|
553
503
|
});
|
|
554
504
|
};
|
|
555
505
|
|
|
556
|
-
/**
|
|
557
|
-
* Send email confirmation code
|
|
558
|
-
* @param {string} email
|
|
559
|
-
* @param {string} token
|
|
560
|
-
* @returns {Promise<object>}
|
|
561
|
-
*/
|
|
562
|
-
const sendEmailConfirmationCode = (email: string, token: string): Promise<object> => {
|
|
563
|
-
return new Promise((resolve, reject) => {
|
|
564
|
-
let postData = {
|
|
565
|
-
email: email,
|
|
566
|
-
};
|
|
567
|
-
let request = client.post(
|
|
568
|
-
"api/v1/users/sendemailconfirmationcode",
|
|
569
|
-
postData,
|
|
570
|
-
{
|
|
571
|
-
headers: { authorization: token },
|
|
572
|
-
}
|
|
573
|
-
);
|
|
574
|
-
request
|
|
575
|
-
.then((response) => {
|
|
576
|
-
resolve(response.data);
|
|
577
|
-
})
|
|
578
|
-
.catch((error) => {
|
|
579
|
-
reject(error);
|
|
580
|
-
});
|
|
581
|
-
});
|
|
582
|
-
};
|
|
583
|
-
|
|
584
506
|
/**
|
|
585
507
|
* Send an email to the user indicated by the email address to reset the password. It returns a promise
|
|
586
|
-
* @param {
|
|
587
|
-
* @returns {Promise<object>}
|
|
508
|
+
* @param {String} email Email of the user who needs to reset the password
|
|
588
509
|
*/
|
|
589
|
-
const sendPasswordResetNotification = (email
|
|
590
|
-
return new Promise((resolve, reject)
|
|
510
|
+
export const sendPasswordResetNotification = (email) => {
|
|
511
|
+
return new Promise(function (resolve, reject) {
|
|
591
512
|
let postData = {
|
|
592
513
|
email: email,
|
|
593
514
|
};
|
|
@@ -607,14 +528,13 @@ const sendPasswordResetNotification = (email: string): Promise<object> => {
|
|
|
607
528
|
|
|
608
529
|
/**
|
|
609
530
|
* Set user profile information
|
|
610
|
-
* @param {
|
|
611
|
-
* @param {
|
|
612
|
-
* @param {
|
|
613
|
-
* @param {
|
|
614
|
-
* @returns {Promise<object>}
|
|
531
|
+
* @param {String} userId User Id
|
|
532
|
+
* @param {String} category User information category
|
|
533
|
+
* @param {String} data New or updated user data information
|
|
534
|
+
* @param {Object} token Authorization token
|
|
615
535
|
*/
|
|
616
|
-
const setUserInformation = (userId
|
|
617
|
-
return new Promise((resolve, reject)
|
|
536
|
+
export const setUserInformation = (userId, category, data, token) => {
|
|
537
|
+
return new Promise(function (resolve, reject) {
|
|
618
538
|
const requestData = {
|
|
619
539
|
data: category ? { [category]: data } : data,
|
|
620
540
|
userId: userId,
|
|
@@ -634,22 +554,14 @@ const setUserInformation = (userId: string, category: string, data: object, toke
|
|
|
634
554
|
|
|
635
555
|
/**
|
|
636
556
|
* Update user email
|
|
637
|
-
* @param {
|
|
638
|
-
* @param {
|
|
639
|
-
* @param {
|
|
640
|
-
* @param {string} token Authorization token
|
|
641
|
-
* @returns {Promise<object>}
|
|
557
|
+
* @param {String} email The new email address
|
|
558
|
+
* @param {String} password The current password
|
|
559
|
+
* @param {String} token Authorization token
|
|
642
560
|
*/
|
|
643
|
-
const updateUserEmail = (
|
|
644
|
-
|
|
645
|
-
verificationCode: string,
|
|
646
|
-
password: string,
|
|
647
|
-
token: string
|
|
648
|
-
): Promise<object> => {
|
|
649
|
-
return new Promise((resolve, reject) => {
|
|
561
|
+
export const updateUserEmail = (email, password, token) => {
|
|
562
|
+
return new Promise(function (resolve, reject) {
|
|
650
563
|
const requestData = {
|
|
651
564
|
email: email,
|
|
652
|
-
verificationCode: verificationCode,
|
|
653
565
|
password: password,
|
|
654
566
|
};
|
|
655
567
|
let confirmationRequest = client.post(
|
|
@@ -671,17 +583,12 @@ const updateUserEmail = (
|
|
|
671
583
|
|
|
672
584
|
/**
|
|
673
585
|
* Update user groups
|
|
674
|
-
* @param {String}
|
|
586
|
+
* @param {String} userIds The id of the user
|
|
675
587
|
* @param {Array<String>} groups The id of the groups the user should belong to
|
|
676
588
|
* @param {String} token Authorization token
|
|
677
|
-
* @returns {Promise<Object>}
|
|
678
589
|
*/
|
|
679
|
-
const updateUserGroups = (
|
|
680
|
-
|
|
681
|
-
groups: string[],
|
|
682
|
-
token: string
|
|
683
|
-
): Promise<object> => {
|
|
684
|
-
return new Promise((resolve, reject) => {
|
|
590
|
+
export const updateUserGroups = (userId, groups, token) => {
|
|
591
|
+
return new Promise(function (resolve, reject) {
|
|
685
592
|
const requestData = {
|
|
686
593
|
userId: userId,
|
|
687
594
|
groups: groups || [],
|
|
@@ -708,14 +615,9 @@ const updateUserGroups = (
|
|
|
708
615
|
* @param {String} password The current password
|
|
709
616
|
* @param {String} newPassword The new password
|
|
710
617
|
* @param {String} token Authorization token
|
|
711
|
-
* @returns {Promise<Object>}
|
|
712
618
|
*/
|
|
713
|
-
const updateUserPassword = (
|
|
714
|
-
|
|
715
|
-
newPassword: string,
|
|
716
|
-
token: string
|
|
717
|
-
): Promise<object> => {
|
|
718
|
-
return new Promise((resolve, reject) => {
|
|
619
|
+
export const updateUserPassword = (password, newPassword, token) => {
|
|
620
|
+
return new Promise(function (resolve, reject) {
|
|
719
621
|
const requestData = {
|
|
720
622
|
password: password,
|
|
721
623
|
newPassword: newPassword,
|
|
@@ -741,18 +643,17 @@ const updateUserPassword = (
|
|
|
741
643
|
* Validate reset password code. It returns a promise
|
|
742
644
|
* @param {String} email User's email address
|
|
743
645
|
* @param {String} code Provided reset code
|
|
744
|
-
* @returns {Promise<Object>}
|
|
745
646
|
*/
|
|
746
|
-
const validateResetPasswordCode = (
|
|
747
|
-
|
|
748
|
-
code: string
|
|
749
|
-
): Promise<object> => {
|
|
750
|
-
return new Promise((resolve, reject) => {
|
|
647
|
+
export const validateResetPasswordCode = (email, code) => {
|
|
648
|
+
return new Promise(function (resolve, reject) {
|
|
751
649
|
let postData = {
|
|
752
650
|
email: email,
|
|
753
651
|
code: code,
|
|
754
652
|
};
|
|
755
|
-
let request = client.post(
|
|
653
|
+
let request = client.post(
|
|
654
|
+
"api/v1/users/validateresetpasswordcode",
|
|
655
|
+
postData
|
|
656
|
+
);
|
|
756
657
|
request
|
|
757
658
|
.then((response) => {
|
|
758
659
|
resolve(response.data);
|
|
@@ -763,7 +664,7 @@ const validateResetPasswordCode = (
|
|
|
763
664
|
});
|
|
764
665
|
};
|
|
765
666
|
|
|
766
|
-
|
|
667
|
+
const users = {
|
|
767
668
|
addAPIToken,
|
|
768
669
|
confirmEmailAddress,
|
|
769
670
|
confirmPhone,
|
|
@@ -778,17 +679,17 @@ export default {
|
|
|
778
679
|
getUsers,
|
|
779
680
|
inviteUsers,
|
|
780
681
|
login,
|
|
781
|
-
loginExchangeKeys,
|
|
782
682
|
logout,
|
|
783
683
|
refreshToken,
|
|
784
684
|
removeAPIToken,
|
|
785
685
|
resendInvitationEmails,
|
|
786
686
|
resetPassword,
|
|
787
|
-
sendEmailConfirmationCode,
|
|
788
687
|
sendPasswordResetNotification,
|
|
789
688
|
setUserInformation,
|
|
790
689
|
updateUserEmail,
|
|
791
690
|
updateUserGroups,
|
|
792
691
|
updateUserPassword,
|
|
793
692
|
validateResetPasswordCode,
|
|
794
|
-
};
|
|
693
|
+
};
|
|
694
|
+
|
|
695
|
+
export default users;
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import dotenv from "dotenv";
|
|
2
|
+
// Load environment variables from .env file
|
|
3
|
+
dotenv.config();
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Convert object to array
|
|
7
|
+
* @param {Object} data
|
|
8
|
+
* @returns {Array}
|
|
9
|
+
*/
|
|
10
|
+
export const objectToArray = (data) => {
|
|
11
|
+
if (typeof data === "object") {
|
|
12
|
+
return [...data];
|
|
13
|
+
} else throw new Error("Invalid type");
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns the backend base API URL
|
|
18
|
+
* @returns {String}
|
|
19
|
+
*/
|
|
20
|
+
export const getBaseUrl = () => {
|
|
21
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "production") {
|
|
22
|
+
return "https://api.stackfactor.io/";
|
|
23
|
+
} else {
|
|
24
|
+
return "http://localhost:3100/";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Remove null properties
|
|
30
|
+
* @param {Object} object
|
|
31
|
+
* @returns {Object}
|
|
32
|
+
*/
|
|
33
|
+
export const removeNullProperties = (object) => {
|
|
34
|
+
Object.keys(object).forEach((key) => {
|
|
35
|
+
let value = object[key.toString()];
|
|
36
|
+
let hasProperties = value && Object.keys(value).length > 0;
|
|
37
|
+
if (value === null) {
|
|
38
|
+
delete object[key.toString()];
|
|
39
|
+
} else if (typeof value !== "string" && hasProperties) {
|
|
40
|
+
removeNullProperties(value);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return object;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const utils = { getBaseUrl, objectToArray, removeNullProperties };
|
|
47
|
+
|
|
48
|
+
export default utils;
|