@stackfactor/client-api 1.1.91 → 1.1.93

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
@@ -5,6 +5,7 @@ import { client } from "./axiosClient.js";
5
5
  * Add a new API Token
6
6
  * @param {Date} expiration Expiration date of the token
7
7
  * @param {String} token Authorization token
8
+ * @returns {Promise}
8
9
  */
9
10
  const addAPIToken = (name, expiration, token) => {
10
11
  return new Promise(function (resolve, reject) {
@@ -36,6 +37,7 @@ const addAPIToken = (name, expiration, token) => {
36
37
  /**
37
38
  * Confirm email address
38
39
  * @param {String} validationCode The code was provided to the user in advance by email
40
+ * @returns {Promise}
39
41
  */
40
42
  const confirmEmailAddress = (validationCode) => {
41
43
  return new Promise(function (resolve, reject) {
@@ -60,6 +62,7 @@ const confirmEmailAddress = (validationCode) => {
60
62
  * Confirm phone number
61
63
  * @param {String} validationCode The code was provided to the user in advance by email
62
64
  * @param {String} token Authorization token
65
+ * @returns {Promise}
63
66
  */
64
67
  const confirmPhone = (validationCode, token) => {
65
68
  return new Promise(function (resolve, reject) {
@@ -87,6 +90,7 @@ const confirmPhone = (validationCode, token) => {
87
90
  * Generate confirmation code
88
91
  * @param {String} phoneNumber Send confirmation code to the phone number
89
92
  * @param {String} token Authorization token
93
+ * @returns {Promise}
90
94
  */
91
95
  const confirmPhoneGenerateCode = (phoneNumber, token) => {
92
96
  return new Promise(function (resolve, reject) {
@@ -118,7 +122,7 @@ const confirmPhoneGenerateCode = (phoneNumber, token) => {
118
122
  * @param {String} password User's password
119
123
  * @param {String} subSite Subsite where the new account will be created
120
124
  * @param {String} inviteCode Invitation code received in advance from one of the account owners
121
- * @param
125
+ * @returns {Promise}
122
126
  */
123
127
  const createAccount = (
124
128
  email,
@@ -166,6 +170,7 @@ const createAccount = (
166
170
  * @param {String} lastName User's last name
167
171
  * @param {String} password User's password
168
172
  * @param {String} token Invitation token provided to the user
173
+ * @returns {Promise}
169
174
  */
170
175
  const createUserAccount = (email, firstName, lastName, password, token) => {
171
176
  return new Promise(function (resolve, reject) {
@@ -201,6 +206,7 @@ const createUserAccount = (email, firstName, lastName, password, token) => {
201
206
  * Delete an existing API token
202
207
  * @param {String} token Expiration date of the token
203
208
  * @param {String} authToken Authorization token
209
+ * @returns {Promise}
204
210
  */
205
211
  const deleteAPIToken = (token, authToken) => {
206
212
  return new Promise(function (resolve, reject) {
@@ -225,6 +231,7 @@ const deleteAPIToken = (token, authToken) => {
225
231
  * Delete existing users
226
232
  * @param {Array<String>} userIds The ID of the users to be deleted
227
233
  * @param {String} token Authorization token
234
+ * @returns {Promise}
228
235
  */
229
236
  const deleteUsers = (userIds, token) => {
230
237
  return new Promise(function (resolve, reject) {
@@ -248,6 +255,7 @@ const deleteUsers = (userIds, token) => {
248
255
  /**
249
256
  * Get all the API tokens
250
257
  * @param {String} token Authorization token
258
+ * @returns {Promise}
251
259
  */
252
260
  const getAPITokens = (token) => {
253
261
  return new Promise(function (resolve, reject) {
@@ -268,6 +276,7 @@ const getAPITokens = (token) => {
268
276
  * Get the specified user account by Id. It returns a promise
269
277
  * @param {String} id Id of the user for which information is being requested
270
278
  * @param {String} token Authorization token
279
+ * @returns {Promise}
271
280
  */
272
281
  const getUserById = (id, token) => {
273
282
  return new Promise(function (resolve, reject) {
@@ -293,6 +302,7 @@ const getUserById = (id, token) => {
293
302
  * @param {String} userId User Id
294
303
  * @param {String} category User information category
295
304
  * @param {String} token Authorization token
305
+ * @returns {Promise}
296
306
  */
297
307
  const getUserInformation = (userId, category, token) => {
298
308
  return new Promise(function (resolve, reject) {
@@ -317,6 +327,7 @@ const getUserInformation = (userId, category, token) => {
317
327
  * @param {Object} filter Filter to select the users. Ex: {firstName : "John"}
318
328
  * @param {Array} fields Fields to be loaded. Ex: ["firstName"]
319
329
  * @param {String} token Authorization token
330
+ * @returns {Promise}
320
331
  */
321
332
  const getUsers = (filter, fields, token) => {
322
333
  return new Promise(function (resolve, reject) {
@@ -343,6 +354,7 @@ const getUsers = (filter, fields, token) => {
343
354
  * @param {String} groupId The group the user should be added to
344
355
  * @param {String} teamId The team the user should be added to
345
356
  * @param {String} token Authorization token
357
+ * @returns {Promise}
346
358
  */
347
359
  const inviteUsers = (invitees, groupId, teamId, authToken) => {
348
360
  return new Promise(function (resolve, reject) {
@@ -369,6 +381,7 @@ const inviteUsers = (invitees, groupId, teamId, authToken) => {
369
381
  * Login using email and password. It returns a promise
370
382
  * @param {String} email User's email address
371
383
  * @param {String} password User's password
384
+ * @returns {Promise}
372
385
  */
373
386
  const login = (email, password) => {
374
387
  return new Promise(function (resolve, reject) {
@@ -387,9 +400,32 @@ const login = (email, password) => {
387
400
  });
388
401
  };
389
402
 
403
+ /**
404
+ * Login callback after authentication. This will exchange the code token for authentication and refresh tokens
405
+ * @param {String} code
406
+ * @returns {Promise}
407
+ * @returns {Promise}
408
+ */
409
+ const loginCallBack = (code) => {
410
+ return new Promise(function (resolve, reject) {
411
+ const requestData = {
412
+ code: code,
413
+ };
414
+ let request = client.post("api/v1/auth/logincallback", requestData);
415
+ request
416
+ .then((response) => {
417
+ resolve(response.data);
418
+ })
419
+ .catch((error) => {
420
+ reject(error);
421
+ });
422
+ });
423
+ };
424
+
390
425
  /**
391
426
  * Logout from the server. It returns a promise
392
427
  * @param {String} token Authorization token
428
+ * @returns {Promise}
393
429
  */
394
430
  const logout = (token) => {
395
431
  return new Promise(function (resolve, reject) {
@@ -414,6 +450,7 @@ const logout = (token) => {
414
450
  * Checks the current auth token and maintain it alive. It returns a promise. In case the token is invalid
415
451
  * a new token can be restablished using login
416
452
  * @param {String} token User's auth token to be refreshed
453
+ * @returns {Promise}
417
454
  */
418
455
  const refreshToken = (refreshToken) => {
419
456
  return new Promise(function (resolve, reject) {
@@ -434,6 +471,7 @@ const refreshToken = (refreshToken) => {
434
471
  * Remove an existing API token
435
472
  * @param {String} id The ID of the token to be removed
436
473
  * @param {String} authToken Authorization token
474
+ * @returns {Promise}
437
475
  */
438
476
  const removeAPIToken = (id, authToken) => {
439
477
  return new Promise(function (resolve, reject) {
@@ -461,6 +499,7 @@ const removeAPIToken = (id, authToken) => {
461
499
  * Resend invitation emails
462
500
  * @param {Array<String>} invitees List of emails of the invitees
463
501
  * @param {String} token Authorization token
502
+ * @returns {Promise}
464
503
  */
465
504
  const resendInvitationEmails = (invitees, authToken) => {
466
505
  return new Promise(function (resolve, reject) {
@@ -486,6 +525,7 @@ const resendInvitationEmails = (invitees, authToken) => {
486
525
  * @param {String} code Code provided to the user by email
487
526
  * @param {String} email User's email address
488
527
  * @param {String} password User's new password
528
+ * @returns {Promise}
489
529
  */
490
530
  const resetPassword = (email, code, password) => {
491
531
  return new Promise(function (resolve, reject) {
@@ -508,6 +548,7 @@ const resetPassword = (email, code, password) => {
508
548
  /**
509
549
  * Send an email to the user indicated by the email address to reset the password. It returns a promise
510
550
  * @param {String} email Email of the user who needs to reset the password
551
+ * @returns {Promise}
511
552
  */
512
553
  const sendPasswordResetNotification = (email) => {
513
554
  return new Promise(function (resolve, reject) {
@@ -534,6 +575,7 @@ const sendPasswordResetNotification = (email) => {
534
575
  * @param {String} category User information category
535
576
  * @param {String} data New or updated user data information
536
577
  * @param {Object} token Authorization token
578
+ * @returns {Promise}
537
579
  */
538
580
  const setUserInformation = (userId, category, data, token) => {
539
581
  return new Promise(function (resolve, reject) {
@@ -559,6 +601,7 @@ const setUserInformation = (userId, category, data, token) => {
559
601
  * @param {String} email The new email address
560
602
  * @param {String} password The current password
561
603
  * @param {String} token Authorization token
604
+ * @returns {Promise}
562
605
  */
563
606
  const updateUserEmail = (email, password, token) => {
564
607
  return new Promise(function (resolve, reject) {
@@ -588,6 +631,7 @@ const updateUserEmail = (email, password, token) => {
588
631
  * @param {String} userIds The id of the user
589
632
  * @param {Array<String>} groups The id of the groups the user should belong to
590
633
  * @param {String} token Authorization token
634
+ * @returns {Promise}
591
635
  */
592
636
  const updateUserGroups = (userId, groups, token) => {
593
637
  return new Promise(function (resolve, reject) {
@@ -617,6 +661,7 @@ const updateUserGroups = (userId, groups, token) => {
617
661
  * @param {String} password The current password
618
662
  * @param {String} newPassword The new password
619
663
  * @param {String} token Authorization token
664
+ * @returns {Promise}
620
665
  */
621
666
  const updateUserPassword = (password, newPassword, token) => {
622
667
  return new Promise(function (resolve, reject) {
@@ -645,6 +690,7 @@ const updateUserPassword = (password, newPassword, token) => {
645
690
  * Validate reset password code. It returns a promise
646
691
  * @param {String} email User's email address
647
692
  * @param {String} code Provided reset code
693
+ * @returns {Promise}
648
694
  */
649
695
  const validateResetPasswordCode = (email, code) => {
650
696
  return new Promise(function (resolve, reject) {
@@ -681,6 +727,7 @@ export default {
681
727
  getUsers,
682
728
  inviteUsers,
683
729
  login,
730
+ loginCallBack,
684
731
  logout,
685
732
  refreshToken,
686
733
  removeAPIToken,
package/lib/utils.js CHANGED
@@ -19,7 +19,22 @@ const objectToArray = (data) => {
19
19
  * @returns {String}
20
20
  */
21
21
  const getBaseUrl = () => {
22
- return process.env.REACT_BACKEND_URL;
22
+ switch (process.env.REACT_APP_NODE_ENV) {
23
+ case "development":
24
+ case null:
25
+ case undefined:
26
+ return "https://localhost/";
27
+ case "testing":
28
+ return "https://qaapi.stackfactor.ai/";
29
+ case "nonprod":
30
+ return "https://api.qa.stackfactor.ai/";
31
+ case "production":
32
+ return "https://api.stackfactor.ai/";
33
+ case "security":
34
+ return "https://csapi.stackfactor.ai/";
35
+ default:
36
+ throw new Error("Invalid environment");
37
+ }
23
38
  };
24
39
 
25
40
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackfactor/client-api",
3
- "version": "1.1.91",
3
+ "version": "1.1.93",
4
4
  "description": "Node.js library for the StackFactor API",
5
5
  "main": "index.js",
6
6
  "exports": {