diff --git a/api/src/services/contentMapper.service.ts b/api/src/services/contentMapper.service.ts index 94a1f4b8..c14b60dd 100644 --- a/api/src/services/contentMapper.service.ts +++ b/api/src/services/contentMapper.service.ts @@ -286,13 +286,12 @@ const getExistingContentTypes = async (req: Request) => { * @throws ExceptionFunction if an error occurs while updating the content type. */ const updateContentType = async (req: Request) => { - const srcFun = "udateContentType"; + const srcFun = "updateContentType"; const { orgId, projectId, contentTypeId } = req.params; const { contentTypeData, token_payload } = req.body; const fieldMapping = contentTypeData?.fieldMapping; - // const updatedContentType: any = {}; - + // Read project data await ProjectModelLowdb.read(); const projectIndex = (await getProjectUtil( projectId, @@ -307,6 +306,7 @@ const updateContentType = async (req: Request) => { )) as number; const project = ProjectModelLowdb.data.projects[projectIndex]; + // Check project status if ( [NEW_PROJECT_STATUS[5], NEW_PROJECT_STATUS[4]].includes(project.status) || project.current_step < STEPPER_STEPS.CONTENT_MAPPING @@ -318,9 +318,13 @@ const updateContentType = async (req: Request) => { token_payload ) ); - throw new BadRequestError(HTTP_TEXTS.CANNOT_UPDATE_CONTENT_MAPPING); + return { + status: 400, + message: HTTP_TEXTS.CANNOT_UPDATE_CONTENT_MAPPING + }; } + // Validate contentTypeData if (isEmpty(contentTypeData)) { logger.error( getLogMessage( @@ -328,14 +332,21 @@ const updateContentType = async (req: Request) => { `${HTTP_TEXTS.INVALID_CONTENT_TYPE} Id: ${contentTypeId}` ) ); - throw new BadRequestError(HTTP_TEXTS.INVALID_CONTENT_TYPE); + return { + status: 400, + message: HTTP_TEXTS.INVALID_CONTENT_TYPE + }; } try { await ContentTypesMapperModelLowdb.read(); + const updateIndex = ContentTypesMapperModelLowdb.chain + .get("ContentTypesMappers") + .findIndex({ id: contentTypeId, projectId: projectId }) + .value(); if (fieldMapping) { - fieldMapping.forEach(async (field: any) => { + for (const field of fieldMapping) { if ( !field.ContentstackFieldType || field.ContentstackFieldType === "" || @@ -351,25 +362,24 @@ const updateContentType = async (req: Request) => { )}` ) ); - await ContentTypesMapperModelLowdb.read(); - ContentTypesMapperModelLowdb.update((data: any) => { - data.ContentTypesMappers[updateIndex].status = - CONTENT_TYPE_STATUS[3]; + await ContentTypesMapperModelLowdb.update((data: any) => { + data.ContentTypesMappers[updateIndex].status = CONTENT_TYPE_STATUS[3]; }); - throw new BadRequestError( - `${VALIDATION_ERRORS.STRING_REQUIRED.replace( + return { + status: 400, + message: `${VALIDATION_ERRORS.STRING_REQUIRED.replace( "$", "ContentstackFieldType or contentstackFieldUid" )}` - ); + }; } - }); + } } - const updateIndex = ContentTypesMapperModelLowdb.chain - .get("ContentTypesMappers") - .findIndex({ id: contentTypeId, projectId: projectId }) - .value(); + // const updateIndex = ContentTypesMapperModelLowdb.chain + // .get("ContentTypesMappers") + // .findIndex({ id: contentTypeId, projectId: projectId }) + // .value(); ContentTypesMapperModelLowdb.update((data: any) => { if (updateIndex >= 0) { data.ContentTypesMappers[updateIndex].otherCmsTitle = @@ -394,12 +404,15 @@ const updateContentType = async (req: Request) => { `${HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND} Id: ${contentTypeId}` ) ); - throw new BadRequestError(HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND); + return { + status: 404, + message: HTTP_TEXTS.CONTENT_TYPE_NOT_FOUND + }; } if (!isEmpty(fieldMapping)) { await FieldMapperModel.read(); - (fieldMapping || []).forEach((field: any) => { + fieldMapping.forEach((field: any) => { const fieldIndex = FieldMapperModel.data.field_mapper.findIndex( (f: any) => f?.id === field?.id ); @@ -411,18 +424,22 @@ const updateContentType = async (req: Request) => { } }); } - await ContentTypesMapperModelLowdb.read(); await ContentTypesMapperModelLowdb.update((data: any) => { data.ContentTypesMappers[updateIndex].status = CONTENT_TYPE_STATUS[2]; }); - // fetch updated data to return in response + + // Fetch and return updated content type await ContentTypesMapperModelLowdb.read(); const updatedContentType = ContentTypesMapperModelLowdb.chain .get("ContentTypesMappers") .find({ id: contentTypeId, projectId: projectId }) .value(); - return { updatedContentType }; + return { + status: 200, + data: { updatedContentType } + }; + } catch (error: any) { logger.error( getLogMessage( @@ -431,12 +448,13 @@ const updateContentType = async (req: Request) => { error ) ); - throw new ExceptionFunction( - error?.message || HTTP_TEXTS.INTERNAL_ERROR, - error?.status || HTTP_CODES.SERVER_ERROR - ); + return { + status: error?.status || 500, + message: error?.message || HTTP_TEXTS.INTERNAL_ERROR + }; } }; + /** * Resets the field mapping and content mapping for a specific content type in a project. * diff --git a/ui/src/components/Card/index.tsx b/ui/src/components/Card/index.tsx index ffd01089..752187f8 100644 --- a/ui/src/components/Card/index.tsx +++ b/ui/src/components/Card/index.tsx @@ -102,7 +102,7 @@ const CardList = ({ project }: ProjectType) => {
- {getDays(project?.updated_at)} + {project?.updated_at && getDays(project?.updated_at)}
diff --git a/ui/src/components/Common/SaveChangesModal/index.tsx b/ui/src/components/Common/SaveChangesModal/index.tsx index e0b76001..25fb5b09 100644 --- a/ui/src/components/Common/SaveChangesModal/index.tsx +++ b/ui/src/components/Common/SaveChangesModal/index.tsx @@ -9,9 +9,9 @@ import { interface Props { closeModal: () => void; - isopen: any; + isopen: (flag: boolean) => void; otherCmsTitle?: string; - saveContentType: () => void; + saveContentType?: () => void; openContentType?: () => void; changeStep?: () => void; dropdownStateChange: () => void; @@ -48,7 +48,7 @@ const SaveChangesModal = (props: Props) => { ) : ( <>{idx + 1} @@ -178,5 +223,6 @@ const HorizontalStepper = forwardRef( ); } ); + HorizontalStepper.displayName = 'HorizontalStepper'; export default HorizontalStepper; diff --git a/ui/src/context/app/app.interface.ts b/ui/src/context/app/app.interface.ts index 01192dea..749bbbf3 100644 --- a/ui/src/context/app/app.interface.ts +++ b/ui/src/context/app/app.interface.ts @@ -10,6 +10,16 @@ export interface ICTA { href: string; } +export type DataProps = { + stepComponentProps: ()=>{}; + currentStep: number; + handleStepChange: (step: number) => void; +}; + +export type SummaryProps = { + stepData: IStep; + stepComponentProps: ()=>{}; +}; interface ContentTypeMap { [key: string]: string; } @@ -70,8 +80,8 @@ export interface IStep { status?: string; lock: boolean; active?: boolean; - data?: (props: any) => JSX.Element; - summery?: (props: any) => JSX.Element; + data?: (props:DataProps) => JSX.Element; + summery?: (props: SummaryProps) => JSX.Element; empty_step_placeholder?: string; } @@ -180,7 +190,7 @@ export interface IMigrationData { testmigrationData: ITestMigration; } -export interface IDropDown { +export interface IDropDown { uid?: string; label: string; value: string; diff --git a/ui/src/pages/Login/index.tsx b/ui/src/pages/Login/index.tsx index 0f343717..f87da3b7 100644 --- a/ui/src/pages/Login/index.tsx +++ b/ui/src/pages/Login/index.tsx @@ -1,9 +1,9 @@ // Libraries -import { FC, useContext, useEffect, useState } from 'react'; +import { FC,useEffect, useState } from 'react'; import { useNavigate, useLocation } from 'react-router-dom'; -import { useDispatch, useSelector } from 'react-redux'; +import { useDispatch } from 'react-redux'; -import { getUserDetails, setAuthToken } from '../../store/slice/authSlice'; +import { setAuthToken } from '../../store/slice/authSlice'; import { Button, Field, @@ -37,8 +37,6 @@ import AccountPage from '../../components/AccountPage'; // Styles import './index.scss'; -import { AppContext } from '../../context/app/app.context'; - const Login: FC = () => { const [data, setData] = useState({}); diff --git a/ui/src/pages/Migration/index.tsx b/ui/src/pages/Migration/index.tsx index 8b65bc9c..b0e0423d 100644 --- a/ui/src/pages/Migration/index.tsx +++ b/ui/src/pages/Migration/index.tsx @@ -24,6 +24,7 @@ import { IFlowStep } from '../../components/Stepper/FlowStepper/flowStep.interface'; import { INewMigration } from '../../context/app/app.interface'; +import { ContentTypeSaveHandles } from '../../components/ContentMapper/contentMapper.interface'; // Components @@ -36,6 +37,13 @@ import TestMigration from '../../components/TestMigration'; import MigrationExecution from '../../components/MigrationExecution'; import { Notification } from '@contentstack/venus-components'; +type StepperComponentRef = { + handleStepChange: (step: number) => void; +}; +type LegacyCmsRef = { + getInternalActiveStepIndex: () => number; +}; + const Migration = () => { const [projectData, setProjectData] = useState(); const [isLoading, setIsLoading] = useState(false); @@ -46,13 +54,13 @@ const Migration = () => { const { projectId = '' } = useParams(); const navigate = useNavigate(); const dispatch = useDispatch(); - const stepperRef = useRef(null); - const legacyCMSRef = useRef(null); + const stepperRef = useRef(null); + const legacyCMSRef = useRef(null); const selectedOrganisation = useSelector((state: RootState)=>state?.authentication?.selectedOrganisation); const newMigrationData = useSelector((state:RootState)=> state?.migration?.newMigrationData); - const saveRef = useRef(null); + const saveRef = useRef(null); useEffect(() => { fetchData(); @@ -140,9 +148,7 @@ const Migration = () => { data: , id:'5', title:'Migration Execution' - }, - - + } ] return steps; } @@ -217,7 +223,7 @@ const Migration = () => { result = 'Imported File'; break; } - if (currentIndex !== 3 || currentIndex !== 4) { + if (currentIndex !== 3) { Notification({ notificationContent: { text: `Please complete ${result} step` }, type: 'warning' @@ -314,7 +320,7 @@ const Migration = () => { dispatch(updateNewMigrationData((newMigrationDataObj))); } - + return (
diff --git a/ui/src/pages/MigrationEditor/index.tsx b/ui/src/pages/MigrationEditor/index.tsx index 9fbceeee..69db889d 100644 --- a/ui/src/pages/MigrationEditor/index.tsx +++ b/ui/src/pages/MigrationEditor/index.tsx @@ -1,11 +1,10 @@ // Libraries -import { useContext, useEffect, useState } from 'react'; +import { useEffect, useState } from 'react'; import { PageHeader, PageLayout } from '@contentstack/venus-components'; import { Params, useNavigate, useParams } from 'react-router'; import { useDispatch, useSelector } from 'react-redux'; // Context -import { AppContext } from '../../context/app/app.context'; import { DEFAULT_NEW_MIGRATION } from '../../context/app/app.interface'; // Service @@ -17,6 +16,7 @@ import NewMigrationWrapper from '../../components/Migrations/NewMigration/NewMig // Style import './index.scss'; import { updateNewMigrationData } from '../../store/slice/migrationDataSlice'; +import { RootState } from '../../store'; const MigrationEditor = () => { const navigate = useNavigate(); @@ -24,7 +24,7 @@ const MigrationEditor = () => { const dispatch = useDispatch(); - const selectedOrganisation = useSelector((state:any)=>state?.authentication?.selectedOrganisation); + const selectedOrganisation = useSelector((state:RootState)=>state?.authentication?.selectedOrganisation); const [projectName, setProjectName] = useState(''); diff --git a/ui/src/pages/Projects/index.tsx b/ui/src/pages/Projects/index.tsx index 2ba3960b..66e5dc54 100644 --- a/ui/src/pages/Projects/index.tsx +++ b/ui/src/pages/Projects/index.tsx @@ -20,8 +20,6 @@ import { ProjectsType, ProjectsObj } from './projects.interface'; import { ModalObj } from '../../components/Modal/modal.interface'; import { CTA } from '../Home/home.interface'; -// Context -import { AppContext } from '../../context/app/app.context'; // Components import ProjectsHeader from '../../components/ProjectsHeader'; @@ -35,6 +33,7 @@ import { NO_PROJECTS, NO_PROJECTS_SEARCH } from '../../common/assets'; import './index.scss'; import { getUserDetails } from '../../store/slice/authSlice'; import useBlockNavigation from '../../hooks/userNavigation'; +import { RootState } from '../../store'; const Projects = () => { @@ -49,7 +48,7 @@ const Projects = () => { } = data; const dispatch = useDispatch(); - const selectedOrganisation = useSelector((state:any)=>state?.authentication?.selectedOrganisation); + const selectedOrganisation = useSelector((state:RootState)=>state?.authentication?.selectedOrganisation); const outputIntro = HTMLReactParser(jsonToHtml(emptystate?.description ?? {})); diff --git a/ui/src/reportWebVitals.js b/ui/src/reportWebVitals.js index 532f29b0..cf1a2121 100644 --- a/ui/src/reportWebVitals.js +++ b/ui/src/reportWebVitals.js @@ -6,6 +6,9 @@ const reportWebVitals = (onPerfEntry) => { getFCP(onPerfEntry); getLCP(onPerfEntry); getTTFB(onPerfEntry); + }) + .catch(error => { + console.error('Error:', error); }); } }; diff --git a/ui/src/scss/App.scss b/ui/src/scss/App.scss index 4e749a23..f295b918 100644 --- a/ui/src/scss/App.scss +++ b/ui/src/scss/App.scss @@ -419,6 +419,11 @@ h2 { border-top: 1px solid $color-brand-secondary-lightest; } } +.list-button { + background: none; + border: 0 none; + width: 100%; +} ::-webkit-input-placeholder { color: $color-stepper-title !important; } diff --git a/ui/src/services/api/login.service.ts b/ui/src/services/api/login.service.ts index 69ee0dc4..acf3300a 100644 --- a/ui/src/services/api/login.service.ts +++ b/ui/src/services/api/login.service.ts @@ -6,15 +6,23 @@ import { postCall } from './service'; export const userSession = (data: User) => { try { return postCall(`${AUTH_ROUTES}/user-session`, data); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; export const requestSMSToken = (data: SmsToken) => { try { return postCall(`${AUTH_ROUTES}/request-token-sms`, data); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in requestSMSToken: ${error.message}`); + } else { + throw new Error('Unknown error in requestSMSToken'); + } } }; diff --git a/ui/src/services/api/migration.service.ts b/ui/src/services/api/migration.service.ts index 833135f9..485bf034 100644 --- a/ui/src/services/api/migration.service.ts +++ b/ui/src/services/api/migration.service.ts @@ -1,3 +1,4 @@ +import { ObjectType } from '../../utilities/constants.interface'; import { API_VERSION } from '../../utilities/constants'; import { getDataFromLocalStorage } from '../../utilities/functions'; import { getCall, postCall, putCall } from './service'; @@ -11,56 +12,80 @@ const options = { export const getMigrationData = (orgId: string, projectId: string) => { try { return getCall(`${API_VERSION}/org/${orgId}/project/${projectId}/`, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in getting migrationData: ${error.message}`); + } else { + throw new Error('Unknown error in getting migrationData'); + } } }; -export const updateLegacyCMSData = (orgId: string, projectId: string, data: any) => { +export const updateLegacyCMSData = (orgId: string, projectId: string, data: ObjectType) => { try { return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/legacy-cms`, data, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; -export const updateAffixData = (orgId: string, projectId: string, data: any) => { +export const updateAffixData = (orgId: string, projectId: string, data: ObjectType) => { try { return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/affix`, data, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; -export const updateFileFormatData = (orgId: string, projectId: string, data: any) => { +export const updateFileFormatData = (orgId: string, projectId: string, data: ObjectType) => { try { return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/file-format`, data, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; -export const updateDestinationStack = (orgId: string, projectId: string, data: any) => { +export const updateDestinationStack = (orgId: string, projectId: string, data: ObjectType) => { try { return putCall( `${API_VERSION}/org/${orgId}/project/${projectId}/destination-stack`, data, options ); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; -export const updateCurrentStepData = (orgId: string, projectId: string, data: any = {}) => { +export const updateCurrentStepData = (orgId: string, projectId: string, data: ObjectType = {}) => { try { return putCall(`${API_VERSION}/org/${orgId}/project/${projectId}/current-step`, data, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; -export const affixConfirmation = (orgId: string, projectId: string, data: any = {}) => { +export const affixConfirmation = (orgId: string, projectId: string, data: ObjectType = {}) => { try { return putCall( `${API_VERSION}/org/${orgId}/project/${projectId}/affix_confirmation`, @@ -72,7 +97,7 @@ export const affixConfirmation = (orgId: string, projectId: string, data: any = } }; -export const fileformatConfirmation = (orgId: string, projectId: string, data: any = {}) => { +export const fileformatConfirmation = (orgId: string, projectId: string, data: ObjectType = {}) => { try { return putCall( `${API_VERSION}/org/${orgId}/project/${projectId}/fileformat_confirmation`, @@ -96,8 +121,12 @@ export const getContentTypes = ( `${API_VERSION}/mapper/contentTypes/${projectId}/${skip}/${limit}/${encodedSearchText}?`, options ); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; @@ -114,16 +143,24 @@ export const getFieldMapping = async ( `${API_VERSION}/mapper/fieldMapping/${projectId}/${contentTypeId}/${skip}/${limit}/${encodedSearchText}?`, options ); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; export const getExistingContentTypes = async (projectId: string) => { try { return await getCall(`${API_VERSION}/mapper/${projectId}`, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; @@ -131,7 +168,7 @@ export const updateContentType = async ( orgId: string, projectId: string, contentTypeId: string, - data: any + data: ObjectType ) => { try { return await putCall( @@ -139,8 +176,12 @@ export const updateContentType = async ( data, options ); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; @@ -148,7 +189,7 @@ export const resetToInitialMapping = async ( orgId: string, projectId: string, contentTypeId: string, - data: any + data: ObjectType ) => { try { return await putCall( @@ -156,12 +197,16 @@ export const resetToInitialMapping = async ( data, options ); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } }; -export const createTestStack = async (orgId: string, projectId: string, data: any) => { +export const createTestStack = async (orgId: string, projectId: string, data: ObjectType) => { try { return await postCall( `${API_VERSION}/migration/test-stack/${orgId}/${projectId}`, @@ -176,8 +221,12 @@ export const createTestStack = async (orgId: string, projectId: string, data: an export const fetchExistingContentType = async (projectId: string, contentTypeUid: string) => { try { return await getCall(`${API_VERSION}/mapper/${projectId}/${contentTypeUid}`, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error'); + } } } diff --git a/ui/src/services/api/project.service.ts b/ui/src/services/api/project.service.ts index dfc36891..118e1b84 100644 --- a/ui/src/services/api/project.service.ts +++ b/ui/src/services/api/project.service.ts @@ -1,3 +1,4 @@ +import { ObjectType } from '../../utilities/constants.interface'; import { API_VERSION } from '../../utilities/constants'; import { getDataFromLocalStorage } from '../../utilities/functions'; import { getCall, postCall, putCall, deleteCall } from './service'; @@ -11,39 +12,59 @@ const options = () => ({ export const getAllProjects = async (orgId: string) => { try { return await getCall(`${API_VERSION}/org/${orgId}/project`, options()); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; export const getProject = async (orgId: string, projectId: string) => { try { return await getCall(`${API_VERSION}/org/${orgId}/project/${projectId}`, options()); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; -export const createProject = async (orgId: string, data: any) => { +export const createProject = async (orgId: string, data: ObjectType) => { try { return await postCall(`${API_VERSION}/org/${orgId}/project/`, data, options()); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; -export const updateProject = async (orgId: string, projectId: string, data: any) => { +export const updateProject = async (orgId: string, projectId: string, data: ObjectType) => { try { return await putCall(`${API_VERSION}/org/${orgId}/project/${projectId}`, data, options()); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; export const deleteProject = async (orgId: string, projectId: string) => { try { return await deleteCall(`${API_VERSION}/org/${orgId}/project/${projectId}`, options()); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; diff --git a/ui/src/services/api/stacks.service.ts b/ui/src/services/api/stacks.service.ts index 334b2b7a..4d8143db 100644 --- a/ui/src/services/api/stacks.service.ts +++ b/ui/src/services/api/stacks.service.ts @@ -19,8 +19,12 @@ export const getAllStacksInOrg = async (orgId: string,searchText: string) => { export const createStacksInOrg = async (orgId: string, data: any) => { try { return await postCall(`${API_VERSION}/org/${orgId}/stacks`, data, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; @@ -30,7 +34,11 @@ export const getStackStatus = async (orgId: string, data: string) => { stack_api_key: data }; return await postCall(`${API_VERSION}/org/${orgId}/stack_status`, stack_api, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; diff --git a/ui/src/services/api/upload.service.ts b/ui/src/services/api/upload.service.ts index ead7f3f2..65437123 100644 --- a/ui/src/services/api/upload.service.ts +++ b/ui/src/services/api/upload.service.ts @@ -1,7 +1,6 @@ import axios from 'axios'; import { UPLOAD_FILE_RELATIVE_URL } from '../../utilities/constants'; -import { User, SmsToken } from '../../pages/Login/login.interface'; -import { API_VERSION } from '../../utilities/constants'; +import { User } from '../../pages/Login/login.interface'; import { getDataFromLocalStorage } from '../../utilities/functions'; //Axios Calls for Upload server @@ -9,8 +8,12 @@ export const getCall = async (url: string, options?: any) => { try { const response = await axios.get(url, { ...options }); return response; - } catch (err: any) { - return err.response; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; @@ -18,8 +21,12 @@ export const postCall = async (url: string, data: User, options?: any) => { try { const response = await axios.post(url, data, options); return response; - } catch (err: any) { - return err.response; + } catch (error) { + if (error instanceof Error) { + throw new Error(`${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; diff --git a/ui/src/services/api/user.service.ts b/ui/src/services/api/user.service.ts index f9668f6b..c19cf14f 100644 --- a/ui/src/services/api/user.service.ts +++ b/ui/src/services/api/user.service.ts @@ -11,8 +11,12 @@ export const getUser = async () => { try { return await getCall(`${API_VERSION}/user/profile`, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; @@ -25,7 +29,11 @@ export const getAllLocales = async (orgId: string) => { try { return await getCall(`${API_VERSION}/org/${orgId}/locales`, options); - } catch (error: any) { - return error; + } catch (error) { + if (error instanceof Error) { + throw new Error(`Error in userSession: ${error.message}`); + } else { + throw new Error('Unknown error in userSession'); + } } }; diff --git a/ui/src/utilities/constants.interface.ts b/ui/src/utilities/constants.interface.ts index 0089b499..deaf0d82 100644 --- a/ui/src/utilities/constants.interface.ts +++ b/ui/src/utilities/constants.interface.ts @@ -1,3 +1,7 @@ export interface ObjectType { - [key: string]: string; + [key: string]: any; } + +export interface Image { + url?: string; +} \ No newline at end of file diff --git a/ui/src/utilities/functions.ts b/ui/src/utilities/functions.ts index 7035f1e3..bcb47920 100644 --- a/ui/src/utilities/functions.ts +++ b/ui/src/utilities/functions.ts @@ -1,5 +1,6 @@ import { Notification } from '@contentstack/venus-components'; import { WEBSITE_BASE_URL } from './constants'; +import { Image, ObjectType } from './constants.interface'; export const Locales = { en: 'en-us', @@ -17,16 +18,16 @@ export const getLocaleCode = (loc = 'en') => { }; // Validate object whether empty or not -export const validateObject = (obj: any) => +export const validateObject = (obj: ObjectType) => Object.keys(obj).length !== 0 && obj.constructor === Object; // Array validation - pass array in and check for length to be more than 0. export const validateArray = (array: T[]) => Array.isArray(array) && array.length > 0; // Use: validateSingleImage(image) -export const validateImage = (image: any) => image && image?.url; +export const validateImage = (image: Image) => image && image?.url; -export const validateLink = (link: any) => link && link?.url; +export const validateLink = (link: Image) => link && link?.url; export const imageWithSiteDomainUrl = (url: string) => { if (WEBSITE_BASE_URL && url?.indexOf('https://images.contentstack.io') > -1) { @@ -68,7 +69,12 @@ export const clearMeasures = (measreName: string, clearAll?: boolean) => { export const extractWindowObj = (str: string): string | null => { const re = /]*>([\s\S]*?)<\/script>/g; - const matches: any = str.match(re); + const matches = str.match(re); + + if (!matches) { + return null; + } + for (const matchStr of matches) { if (matchStr.includes('window.sso')) { return matchStr.replace('', ''); @@ -100,7 +106,7 @@ export const setDataInLocalStorage = (key: string, data: any) => { return true; }; -export const getDays = (day: any) => { +export const getDays = (day: string | number | Date) => { const presentDay = new Date().getTime(); const projectDate = new Date(day).getTime(); const time = presentDay - projectDate; diff --git a/uplaode-api/migration-sitecore/libs/reference.js b/uplaode-api/migration-sitecore/libs/reference.js index d4f3ba13..31bafd40 100644 --- a/uplaode-api/migration-sitecore/libs/reference.js +++ b/uplaode-api/migration-sitecore/libs/reference.js @@ -96,7 +96,7 @@ function ExtractRef() { otherCmsType: "reference", contentstackField: newKey, contentstackFieldUid: uidCorrector({ uid: newKey }), - ContentstackFieldType: "refernce", + ContentstackFieldType: "reference", isDeleted: false, backupFieldType: "reference", refrenceTo: key, diff --git a/uplaode-api/package.json b/uplaode-api/package.json index 382b021b..17a4b39f 100644 --- a/uplaode-api/package.json +++ b/uplaode-api/package.json @@ -31,7 +31,7 @@ "typescript": "^5.3.3" }, "dependencies": { - "@aws-sdk/client-s3": "^3.490.0", + "@aws-sdk/client-s3": "^3.529.0", "@contentstack/cli-utilities": "^1.5.12", "@typescript-eslint/parser": "^7.7.1", "axios": "^1.6.8", @@ -52,4 +52,4 @@ "node-fetch": "^2.7.0", "prettier": "^2.7.1" } -} \ No newline at end of file +} diff --git a/uplaode-api/src/services/fileProcessing.ts b/uplaode-api/src/services/fileProcessing.ts index 4a92b700..5df0fe6b 100644 --- a/uplaode-api/src/services/fileProcessing.ts +++ b/uplaode-api/src/services/fileProcessing.ts @@ -10,7 +10,7 @@ const handleFileProcessing = async (fileExt: string, zipBuffer: any, cmsType: st if (fileExt === 'zip') { const zip = new JSZip(); await zip.loadAsync(zipBuffer); - if (await validator({ data: zip, type: cmsType, extension: fileExt })) { + if (validator({ data: zip, type: cmsType, extension: fileExt })) { const isSaved = await saveZip(zip); if (isSaved) { logger.info('Validation success:', { @@ -38,7 +38,7 @@ const handleFileProcessing = async (fileExt: string, zipBuffer: any, cmsType: st // if file is not zip // Convert the buffer to a string assuming it's UTF-8 encoded const jsonString = Buffer?.from?.(zipBuffer)?.toString?.('utf8'); - if (await validator({ data: jsonString, type: cmsType, extension: fileExt })) { + if (validator({ data: jsonString, type: cmsType, extension: fileExt })) { logger.info('Validation success:', { status: HTTP_CODES?.OK, message: HTTP_TEXTS?.VALIDATION_SUCCESSFULL, diff --git a/uplaode-api/tsconfig.json b/uplaode-api/tsconfig.json index 51793fe2..dbb6d8bb 100644 --- a/uplaode-api/tsconfig.json +++ b/uplaode-api/tsconfig.json @@ -32,7 +32,7 @@ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + "typeRoots": ["./node_modules/@types", "./expree.d.ts"], /* Specify multiple folders that act like './node_modules/@types'. */ // "types": [], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ @@ -107,6 +107,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["src/**/*.ts"], + "include": ["src/**/*.ts", "express.d.ts"], "exclude": ["node_modules", "build"] }