Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/credebl/studio into api-…
Browse files Browse the repository at this point in the history
…standardization-for-schema-module

Signed-off-by: karan <[email protected]>
  • Loading branch information
16-karan committed Sep 20, 2023
2 parents 07379fe + 326076a commit ad89c21
Show file tree
Hide file tree
Showing 33 changed files with 924 additions and 1,139 deletions.
458 changes: 227 additions & 231 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"socket.io-client": "^4.6.2",
"tailwind-scrollbar": "^3.0.4",
"tailwindcss": "^3.3.3",
"uuidv4": "^6.2.13",
"uuid": "^9.0.1",
"yup": "^1.2.0"
},
"devDependencies": {
Expand All @@ -75,6 +75,7 @@
"@types/downloadjs": "^1.4.3",
"@types/eslint": "^8.21.1",
"@types/secure-random-password": "^0.2.1",
"@types/uuid": "^9.0.3",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"astro-eslint-parser": "^0.11.0",
Expand Down
2 changes: 1 addition & 1 deletion src/api/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { storageKeys } from "../config/CommonConstant";
export const getAgentHealth = async (orgId:number) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.Agent.checkAgentHealth}?orgId=${orgId}`,
url: `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Agent.checkAgentHealth}`,
config: {
headers: {
'Content-type': 'application/json',
Expand Down
33 changes: 10 additions & 23 deletions src/api/Auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {axiosGet, axiosPost, axiosPut} from '../services/apiRequests'
import { number, string } from 'yup'

import type { AxiosError } from 'axios'
import CryptoJS from "crypto-js"
import { apiRoutes } from '../config/apiRoutes'
import { envConfig } from '../config/envConfig'
Expand All @@ -12,7 +9,8 @@ export interface UserSignUpData {
email: string,
}
export interface AddPasswordDetails {
password?:string
email:string
password:string
isPasskey:boolean
firstName: string|null
lastName: string|null
Expand Down Expand Up @@ -61,7 +59,7 @@ export const loginUser = async(payload: UserSignInData) => {

export const getUserProfile = async(accessToken: string) => {
const details = {
url: apiRoutes.auth.userProfile,
url: apiRoutes.users.userProfile,
config : { headers: { Authorization: `Bearer ${accessToken}` } }
}
try{
Expand Down Expand Up @@ -98,7 +96,6 @@ export const updateUserProfile = async(data: object ) => {
const err = error as Error
return err?.message
}

}

export const verifyUserMail = async(payload: EmailVerifyData ) => {
Expand All @@ -113,14 +110,12 @@ export const verifyUserMail = async(payload: EmailVerifyData ) => {
catch(error){
const err = error as Error
return err?.message
}


}
}

export const checkUserExist = async(payload: string) => {
const details ={
url:`${apiRoutes.auth.checkUser}${payload}`,
url:`${apiRoutes.users.checkUser}${payload}`,
config: { headers: { "Content-type": "application/json" } }
}
try{
Expand All @@ -130,15 +125,12 @@ export const checkUserExist = async(payload: string) => {
catch(error){
const err = error as Error
return err?.message
}


}
}

export const addPasswordDetails = async(payload: AddPasswordDetails, email:string) => {
// Api call to add password
export const addPasswordDetails = async(payload: AddPasswordDetails) => {
const details ={
url: `${apiRoutes.auth.addDetails}${email}`,
url: `${apiRoutes.auth.addDetails}`,
payload,
config: { headers: { "Content-type": "application/json" } }
}
Expand All @@ -149,9 +141,7 @@ export const addPasswordDetails = async(payload: AddPasswordDetails, email:strin
catch(error){
const err = error as Error
return err?.message
}


}
}

export const addPasskeyUserDetails = async(payload: AddPassword, email:string) => {
Expand All @@ -171,12 +161,9 @@ export const addPasskeyUserDetails = async(payload: AddPassword, email:string) =
catch(error){
const err = error as Error
return err?.message
}


}
}


export const passwordEncryption = (password: string): string => {
const CRYPTO_PRIVATE_KEY: string = `${envConfig.PUBLIC_CRYPTO_PRIVATE_KEY}`
const encryptedPassword: string = CryptoJS.AES.encrypt(JSON.stringify(password), CRYPTO_PRIVATE_KEY).toString()
Expand Down
2 changes: 1 addition & 1 deletion src/api/Fido.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateRegistrationOption = async (payload: RegistrationOptionInte
}
}

export const verifyRegistration = async (payload:unknown, userEmail:string) => {
export const verifyRegistration = async (payload:verifyRegistrationObjInterface, userEmail:string) => {
const token = await getFromLocalStorage(storageKeys.TOKEN)
const details = {
url: `${apiRoutes.fido.verifyRegistration}${userEmail}`,
Expand Down
11 changes: 7 additions & 4 deletions src/api/invitations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export const getOrganizationInvitations = async (pageNumber: number, pageSize: n

const orgId = await getFromLocalStorage(storageKeys.ORG_ID)

const url = `${apiRoutes.organizations.invitations}/${orgId}?pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}`
if (!orgId) {
return "Organization is required";
}

const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.invitations}?&pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}`

const token = await getFromLocalStorage(storageKeys.TOKEN)

Expand Down Expand Up @@ -36,7 +40,7 @@ export const createInvitations = async (invitationList: Array<object>) => {

const orgId = await getFromLocalStorage(storageKeys.ORG_ID)

const url = apiRoutes.organizations.invitations
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.invitations}`
const payload = {
invitations: invitationList,
orgId: Number(orgId)
Expand Down Expand Up @@ -94,10 +98,9 @@ export const getUserInvitations = async (pageNumber: number, pageSize: number, s
// Accept/ Reject Invitations
export const acceptRejectInvitations = async (invitationId: number,orgId: number, status: string) => {

const url = apiRoutes.users.invitations
const url = `${apiRoutes.users.invitations}/${invitationId}`

const payload = {
invitationId,
orgId: Number(orgId),
status
}
Expand Down
24 changes: 14 additions & 10 deletions src/api/organization.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { axiosGet, axiosPost, axiosPublicUserGet, axiosPut } from "../services/apiRequests"
import { axiosGet, axiosPost, axiosPut } from "../services/apiRequests"

import { apiRoutes } from "../config/apiRoutes";
import { getFromLocalStorage } from "./Auth";
Expand Down Expand Up @@ -32,9 +32,9 @@ export const createOrganization = async (data: object) => {
}
}

export const updateOrganization = async (data: object) => {
export const updateOrganization = async (data: object, orgId:string) => {

const url = apiRoutes.organizations.update
const url = `${apiRoutes.organizations.update}/${orgId}`
const payload = data
const token = await getFromLocalStorage(storageKeys.TOKEN)

Expand Down Expand Up @@ -114,7 +114,7 @@ export const getOrganizationById = async (orgId: string) => {

export const getOrgDashboard = async (orgId: string) => {

const url = `${apiRoutes.organizations.getOrgDashboard}?orgId=${Number(orgId)}`
const url = `${apiRoutes.organizations.getOrgDashboard}/${orgId}`

const token = await getFromLocalStorage(storageKeys.TOKEN)

Expand All @@ -138,9 +138,9 @@ export const getOrgDashboard = async (orgId: string) => {
}
}

export const spinupDedicatedAgent = async (data: object) => {
export const spinupDedicatedAgent = async (data: object, orgId:number) => {

const url = apiRoutes.organizations.agentDedicatedSpinup
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Agent.agentDedicatedSpinup}`
const payload = data

const token = await getFromLocalStorage(storageKeys.TOKEN)
Expand All @@ -166,9 +166,9 @@ export const spinupDedicatedAgent = async (data: object) => {
}
}

export const spinupSharedAgent = async (data: object) => {
export const spinupSharedAgent = async (data: object, orgId:number) => {

const url = apiRoutes.organizations.agentSharedSpinup
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Agent.agentSharedSpinup}`
const payload = data

const token = await getFromLocalStorage(storageKeys.TOKEN)
Expand Down Expand Up @@ -226,8 +226,11 @@ export const getOrganizationRoles = async () => {
export const getOrganizationUsers = async (pageNumber: number, pageSize: number, search = '') => {

const orgId = await getFromLocalStorage(storageKeys.ORG_ID)
if (!orgId) {
return "Organization is required";
}

const url = `${apiRoutes.users.fetchUsers}?orgId=${orgId}&pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}`
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.users.fetchUsers}?&pageNumber=${pageNumber}&pageSize=${pageSize}&search=${search}`

const axiosPayload = {
url,
Expand All @@ -248,7 +251,7 @@ export const editOrganizationUserRole = async (userId: number, roles: number[])

const orgId = await getFromLocalStorage(storageKeys.ORG_ID)

const url = apiRoutes.organizations.editUserROle
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.organizations.editUserROle}/${userId}`
const payload = {
orgId,
userId,
Expand Down Expand Up @@ -343,3 +346,4 @@ export const getPublicOrganizations = async (pageNumber: number, pageSize: numbe
return err?.message
}
}

2 changes: 1 addition & 1 deletion src/components/Authentication/ResetPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import FooterBar from './FooterBar.js';
import NavBar from './NavBar.js';
import { addPasskeyUserDetails, passwordEncryption, setToLocalStorage } from '../../api/Auth.js';
import type { AxiosResponse } from 'axios';
import React from 'react';
import { PassInvisible, PassVisible, SignUpArrow } from './Svg.js';
import React from 'react';

interface passwordValues {
password: string;
Expand Down
1 change: 0 additions & 1 deletion src/components/Authentication/SignInUserPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const SignInUserPasskey = (signInUserProps: signInUserProps) => {
...attResp,
challangeId
};
setFidoLoader(false)
const verificationResp = await verifyAuthenticationMethod(verifyAuthenticationObj, { userName: email });
const { data } = verificationResp as AxiosResponse
if (data?.data.verified) {
Expand Down
16 changes: 6 additions & 10 deletions src/components/Authentication/SignInUserPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import {
Form,
Formik,
} from 'formik';
import React, { useState } from 'react';
import { apiStatusCodes, storageKeys } from '../../config/CommonConstant';
import { getUserProfile, loginUser, passwordEncryption, setToLocalStorage } from '../../api/Auth';

import { Alert } from 'flowbite-react';
import type { AxiosResponse } from 'axios';
import CustomSpinner from '../CustomSpinner';
import FooterBar from './FooterBar';
import NavBar from './NavBar';
import SignInUserPasskey from './SignInUserPasskey';
import { getSupabaseClient } from '../../supabase';
import NavBar from './NavBar';
import FooterBar from './FooterBar';
import React, { useState } from 'react';

interface emailValue {
email: string;
Expand Down Expand Up @@ -47,23 +47,22 @@ const SignInUserPassword = (signInUserProps: SignInUser3Props) => {


const getUserDetails = async (access_token: string) => {

const userDetails = await getUserProfile(access_token);
const { data } = userDetails as AxiosResponse
if (data?.data?.userOrgRoles?.length > 0) {

const permissionArray: number | string[] = []
data?.data?.userOrgRoles?.forEach((element: { orgRole: { name: string } }) => permissionArray.push(element?.orgRole?.name));
await setToLocalStorage(storageKeys.PERMISSIONS, permissionArray)
await setToLocalStorage(storageKeys.USER_PROFILE, data?.data)
await setToLocalStorage(storageKeys.USER_EMAIL, data?.data?.email)

window.location.href = '/dashboard'
} else {
setFailure(userDetails as string)
}

setLoading(false)
}


const signInUser = async (values: passwordValue) => {
const payload: SignInUser3Props = {
email: email,
Expand All @@ -73,10 +72,8 @@ const SignInUserPassword = (signInUserProps: SignInUser3Props) => {
setLoading(true)
const loginRsp = await loginUser(payload)
const { data } = loginRsp as AxiosResponse

if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
await setToLocalStorage(storageKeys.TOKEN, data?.data?.access_token)

const response = await fetch('/api/auth/signin', {
method: "POST",
headers: {
Expand All @@ -88,7 +85,6 @@ const SignInUserPassword = (signInUserProps: SignInUser3Props) => {
if (response.redirected) {
getUserDetails(data?.data?.access_token)
}

} else {
setLoading(false)
setFailure(loginRsp as string)
Expand Down
8 changes: 5 additions & 3 deletions src/components/Authentication/SignUpUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const SignUpUser = () => {
setVerifyLoader(true)
const userRsp = await sendVerificationMail(payload);
const { data } = userRsp as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {

setVerificationSuccess(data?.message)
setVerifyLoader(false)
Expand All @@ -68,12 +68,14 @@ const SignUpUser = () => {
const userRsp = await checkUserExist(values?.email)
const { data } = userRsp as AxiosResponse
setLoading(false)
console.log("data:56576", data)
if (data?.statusCode === apiStatusCodes.API_STATUS_SUCCESS) {
if (data.data === 'New User') {
if (data?.data?.isExist === false) {
console.log('email data::', data.data)
setEmail(values?.email)
await VerifyMail(values?.email)
}
else if (data.data.isEmailVerified === true && data?.data?.isKeycloak !== true) {
else if (data.data.isEmailVerified === true && data?.data?.isSupabase!== true) {
setEmail(values?.email)
await setToLocalStorage(storageKeys.USER_EMAIL, values?.email)
setNextFlag(true)
Expand Down
7 changes: 5 additions & 2 deletions src/components/Authentication/SignUpUserPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface passwordValues {
confirmPassword: string
}

const SignUpUserPasskey = ({ firstName, lastName }: { firstName: string; lastName: string }) => {
const SignUpUserPasskey = ({ email,firstName, lastName }: { email:string,firstName: string; lastName: string }) => {

const [loading, setLoading] = useState<boolean>(false)
const [erroMsg, setErrMsg] = useState<string | null>(null)
Expand Down Expand Up @@ -63,17 +63,19 @@ const SignUpUserPasskey = ({ firstName, lastName }: { firstName: string; lastNam
const userEmail = await getFromLocalStorage(storageKeys.USER_EMAIL)
const password: string = uuidv4();
let payload: AddPasswordDetails = {
email: userEmail,
isPasskey: fidoFlag,
firstName: firstName,
lastName: lastName,
password: passwordEncryption(password)
};
if (!fidoFlag) {

payload.password = passwordDetails?.password;
}
setLoading(true)

const userRsp = await addPasswordDetails(payload, userEmail)
const userRsp = await addPasswordDetails(payload)
const { data } = userRsp as AxiosResponse
setLoading(false)
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {
Expand Down Expand Up @@ -317,6 +319,7 @@ const SignUpUserPasskey = ({ firstName, lastName }: { firstName: string; lastNam
{
currentComponent === 'password' && (
<SignUpUserPassword
email={email}
firstName={firstName}
lastName={lastName}
/>
Expand Down
Loading

0 comments on commit ad89c21

Please sign in to comment.