diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..9a2a0e2 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v20 diff --git a/apps/leafcutter/.gitpod.Dockerfile b/apps/leafcutter/.gitpod.Dockerfile deleted file mode 100644 index c97d130..0000000 --- a/apps/leafcutter/.gitpod.Dockerfile +++ /dev/null @@ -1,15 +0,0 @@ -FROM gitpod/workspace-full - -# set up aws -RUN rm -rf ~/.aws -RUN mkdir ~/.aws -RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/home/gitpod/awscliv2.zip" -RUN unzip ~/awscliv2.zip -d ~/awscliv2 -RUN sudo ~/awscliv2/aws/install --update -RUN brew install aws-vault - -RUN brew install kubectl -RUN brew install pipx -RUN pipx install aws-sso-util -RUN npm i -g prettier -RUN npm i -g npm-check-updates diff --git a/apps/leafcutter/.gitpod.yml b/apps/leafcutter/.gitpod.yml deleted file mode 100644 index abdbf62..0000000 --- a/apps/leafcutter/.gitpod.yml +++ /dev/null @@ -1,6 +0,0 @@ -tasks: - - init: npm install - command: npm run dev - -image: - file: .gitpod.Dockerfile diff --git a/apps/leafcutter/components/AboutBox.tsx b/apps/leafcutter/components/AboutBox.tsx index d09efa5..c8d06e9 100644 --- a/apps/leafcutter/components/AboutBox.tsx +++ b/apps/leafcutter/components/AboutBox.tsx @@ -1,12 +1,15 @@ -import { FC } from "react"; +import { FC, PropsWithChildren } from "react"; import { Box } from "@mui/material"; import { useAppContext } from "./AppProvider"; -interface AboutBoxProps { +type AboutBoxProps = PropsWithChildren<{ backgroundColor: string; -} +}>; -export const AboutBox: FC = ({ backgroundColor, children }: any) => { +export const AboutBox: FC = ({ + backgroundColor, + children, +}: any) => { const { colors: { white }, } = useAppContext(); diff --git a/apps/leafcutter/components/AccountButton.tsx b/apps/leafcutter/components/AccountButton.tsx index ae6fa3c..c4311e3 100644 --- a/apps/leafcutter/components/AccountButton.tsx +++ b/apps/leafcutter/components/AccountButton.tsx @@ -36,7 +36,7 @@ export const AccountButton: FC = () => { }, }} > - account + account typeof image === "string" ? `${basePath}${image}` : `${basePath}${image.src}`; @@ -9,16 +18,16 @@ const AppContext = createContext({ colors, typography, imageURL, - query: null, - updateQuery: null, - updateQueryType: null, - replaceQuery: null, - clearQuery: null, + query: null as any, + updateQuery: null as any, + updateQueryType: null as any, + replaceQuery: null as any, + clearQuery: null as any, foundCount: 0, - setFoundCount: null, + setFoundCount: null as any, }); -export const AppProvider: FC = ({ children }) => { +export const AppProvider: FC = ({ children }) => { const initialState = { incidentType: { display: "Incident Type", @@ -82,7 +91,10 @@ export const AppProvider: FC = ({ children }) => { }, }; const reducer = (state: any, action: any) => { - const key = action.payload ? Object.keys(action.payload)[0] : null; + const key = action.payload?.[0]; + if (!key) { + throw new Error("Unknown key"); + } const newState = { ...state }; switch (action.type) { case "UPDATE": diff --git a/apps/leafcutter/components/GettingStartedDialog.tsx b/apps/leafcutter/components/GettingStartedDialog.tsx index df9fcec..1e5f94c 100644 --- a/apps/leafcutter/components/GettingStartedDialog.tsx +++ b/apps/leafcutter/components/GettingStartedDialog.tsx @@ -5,7 +5,19 @@ import { useRouter } from "next/router"; import { useTranslate } from "react-polyglot"; import { useAppContext } from "./AppProvider"; -const CheckboxItem = ({ title, description, checked, onChange }) => { +type CheckboxItemProps = { + title: string; + description: string; + checked: boolean; + onChange: () => void; +}; + +const CheckboxItem: FC = ({ + title, + description, + checked, + onChange, +}) => { const { typography: { p, small }, } = useAppContext(); @@ -48,10 +60,10 @@ export const GettingStartedDialog: FC = () => { typography: { h4 }, } = useAppContext(); const t = useTranslate(); - const [completedItems, setCompletedItems] = useState([]); + const [completedItems, setCompletedItems] = useState([] as any[]); const router = useRouter(); const open = router.query.tooltip?.toString() === "checklist"; - const toggleCompletedItem = (item) => { + const toggleCompletedItem = (item: any) => { if (completedItems.includes(item)) { setCompletedItems(completedItems.filter((i) => i !== item)); } else { diff --git a/apps/leafcutter/components/LanguageSelect.tsx b/apps/leafcutter/components/LanguageSelect.tsx index 9b02b32..e8b4fbf 100644 --- a/apps/leafcutter/components/LanguageSelect.tsx +++ b/apps/leafcutter/components/LanguageSelect.tsx @@ -14,7 +14,7 @@ export const LanguageSelect = () => { colors: { white, leafcutterElectricBlue }, } = useAppContext(); const router = useRouter(); - const locales = { en: "English", fr: "Français" }; + const locales: any = { en: "English", fr: "Français" }; const popupState = usePopupState({ variant: "popover", popupId: "language" }); return ( @@ -36,7 +36,7 @@ export const LanguageSelect = () => { }, }} > - {locales[router.locale] ?? locales.en} + {locales[router.locale as any] ?? locales.en} diff --git a/apps/leafcutter/components/Layout.tsx b/apps/leafcutter/components/Layout.tsx index 98e70b4..5fcc052 100644 --- a/apps/leafcutter/components/Layout.tsx +++ b/apps/leafcutter/components/Layout.tsx @@ -1,3 +1,4 @@ +import { FC, PropsWithChildren } from "react"; import { Grid, Container } from "@mui/material"; import CookieConsent from "react-cookie-consent"; import { useCookies } from "react-cookie"; @@ -7,7 +8,7 @@ import { GettingStartedDialog } from "./GettingStartedDialog"; import { useAppContext } from "./AppProvider"; // import { Footer } from "./Footer"; -export const Layout = ({ children }) => { +export const Layout: FC = ({ children }) => { const [cookies, setCookie] = useCookies(["cookieConsent"]); const consentGranted = cookies.cookieConsent === "true"; const { diff --git a/apps/leafcutter/components/PageHeader.tsx b/apps/leafcutter/components/PageHeader.tsx index a0b0eb0..46c31d2 100644 --- a/apps/leafcutter/components/PageHeader.tsx +++ b/apps/leafcutter/components/PageHeader.tsx @@ -1,12 +1,12 @@ /* eslint-disable react/require-default-props */ -import { FC } from "react"; +import { FC, PropsWithChildren } from "react"; import { Box } from "@mui/material"; import { useAppContext } from "./AppProvider"; -interface PageHeaderProps { +type PageHeaderProps = PropsWithChildren<{ backgroundColor: string; sx?: any; -} +}>; export const PageHeader: FC = ({ backgroundColor, diff --git a/apps/leafcutter/components/QueryBuilderSection.tsx b/apps/leafcutter/components/QueryBuilderSection.tsx index 5352d35..99dad2e 100644 --- a/apps/leafcutter/components/QueryBuilderSection.tsx +++ b/apps/leafcutter/components/QueryBuilderSection.tsx @@ -1,4 +1,4 @@ -import { FC, useState } from "react"; +import { FC, PropsWithChildren, useState } from "react"; import { Box, Grid, @@ -29,7 +29,14 @@ interface QueryBuilderSectionProps { tooltipDescription: string; } -const Tooltip = ({ title, description, children, open }) => { +type TooltipProps = PropsWithChildren<{ + title: string; + description: string; + children: any; + open: boolean; +}>; + +const Tooltip: FC = ({ title, description, children, open }) => { const { colors: { white, leafcutterElectricBlue, almostBlack }, typography: { h5, small }, diff --git a/apps/leafcutter/components/QueryDateRangeSelector.tsx b/apps/leafcutter/components/QueryDateRangeSelector.tsx index 8c42968..bc8c82e 100644 --- a/apps/leafcutter/components/QueryDateRangeSelector.tsx +++ b/apps/leafcutter/components/QueryDateRangeSelector.tsx @@ -63,6 +63,7 @@ export const QueryDateRangeSelector: FC = () => { startDate: { values: [date] }, }); }} + // @ts-ignore renderInput={(params) => ( = () => { endDate: { values: [date] }, }); }} + // @ts-ignore renderInput={(params) => ( = ({ values, width, }) => { - const [selectionModel, setSelectionModel] = useState([]); + const [selectionModel, setSelectionModel] = useState([] as any[]); const { colors: { leafcutterLightBlue, pink, leafcutterElectricBlue, warningPink }, typography: { small }, @@ -70,19 +70,19 @@ export const QueryListSelector: FC = ({ rows={rows} columns={columns} density="compact" - pageSize={100} + pageSizeOptions={[100]} checkboxSelection - disableSelectionOnClick + disableRowSelectionOnClick hideFooter disableColumnMenu scrollbarSize={10} - onSelectionModelChange={(newSelectionModel) => { + onRowSelectionModelChange={(newSelectionModel) => { setSelectionModel(newSelectionModel); updateQuery({ [keyName]: { values: newSelectionModel }, }); }} - selectionModel={selectionModel} + rowSelectionModel={selectionModel} /> diff --git a/apps/leafcutter/components/QueryText.tsx b/apps/leafcutter/components/QueryText.tsx index 9eea8e2..cffc7d0 100644 --- a/apps/leafcutter/components/QueryText.tsx +++ b/apps/leafcutter/components/QueryText.tsx @@ -12,7 +12,7 @@ export const QueryText: FC = () => { query: q, } = useAppContext(); - const displayNames = { + const displayNames: any = { incidentType: t("incidentType"), startDate: t("startDate"), endDate: t("endDate"), @@ -41,6 +41,7 @@ export const QueryText: FC = () => { queryType === "include" ? ` ${t("is")} ` : ` ${t("isNot")} ` } ${values .map( + // @ts-expect-error (value: string) => `${taxonomy[key]?.[value]?.display ?? ""}` ) .join(` ${t("or")} `)}`; diff --git a/apps/leafcutter/components/RawDataViewer.tsx b/apps/leafcutter/components/RawDataViewer.tsx index 32cc569..bad2385 100644 --- a/apps/leafcutter/components/RawDataViewer.tsx +++ b/apps/leafcutter/components/RawDataViewer.tsx @@ -16,7 +16,7 @@ export const RawDataViewer: FC = ({ rows, height }) => { headerName: t("date"), editable: false, flex: 0.7, - valueFormatter: ({ value }) => new Date(value).toLocaleDateString(), + valueFormatter: ({ value }: any) => new Date(value).toLocaleDateString(), }, { field: "incident", @@ -58,7 +58,10 @@ export const RawDataViewer: FC = ({ rows, height }) => { return ( - e.stopPropagation()}> + e.stopPropagation()} + > = ({ rows, height }) => { rows={rows} columns={columns} density="compact" - pageSize={100} - disableSelectionOnClick + pageSizeOptions={[100]} + disableRowSelectionOnClick hideFooter disableColumnMenu scrollbarSize={10} @@ -76,6 +79,6 @@ export const RawDataViewer: FC = ({ rows, height }) => { - + ); }; diff --git a/apps/leafcutter/components/VisualizationBuilder.tsx b/apps/leafcutter/components/VisualizationBuilder.tsx index d71fa4a..81f2295 100644 --- a/apps/leafcutter/components/VisualizationBuilder.tsx +++ b/apps/leafcutter/components/VisualizationBuilder.tsx @@ -49,8 +49,9 @@ export const VisualizationBuilder: FC = ({ clearQuery, } = useAppContext(); const { visualizations } = visualizationMap; - const [selectedVisualizationType, setSelectedVisualizationType] = - useState(null); + const [selectedVisualizationType, setSelectedVisualizationType] = useState( + null as any + ); const toggleSelectedVisualizationType = (visualizationType: string) => { if (visualizationType === selectedVisualizationType) { setSelectedVisualizationType(null); @@ -72,7 +73,7 @@ export const VisualizationBuilder: FC = ({ updateSearches(); }, [setSavedSearches]); - const showSavedSearchPopup = (event) => { + const showSavedSearchPopup = (event: any) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { @@ -104,8 +105,10 @@ export const VisualizationBuilder: FC = ({ const updateSearch = (name: string) => { handleClose(); closeDialog(); - const found = savedSearches.find((search) => search.name === name); - replaceQuery(found.query); + const found: any = savedSearches.find( + (search: any) => search.name === name + ); + replaceQuery(found?.query); }; const clearSearch = () => clearQuery(); @@ -240,7 +243,7 @@ export const VisualizationBuilder: FC = ({ {t("saveCurrentSearch")} - {savedSearches.map((savedSearch) => ( + {savedSearches.map((savedSearch: any) => ( updateSearch(savedSearch.name)} @@ -322,6 +325,7 @@ export const VisualizationBuilder: FC = ({ = ({ const { id, type, title, description } = template; const cleanTitle = title .replace("Templated", "") + // @ts-expect-error .replace(visualizations[type].name, ""); const metricType = cleanTitle.replace(/\s/g, "").toLowerCase(); return ( diff --git a/apps/leafcutter/components/VisualizationSelectCard.tsx b/apps/leafcutter/components/VisualizationSelectCard.tsx index 2a078b8..571c0e3 100644 --- a/apps/leafcutter/components/VisualizationSelectCard.tsx +++ b/apps/leafcutter/components/VisualizationSelectCard.tsx @@ -37,7 +37,7 @@ export const VisualizationSelectCard: FC = ({ cdrLinkOrange, }, } = useAppContext(); - const images = { + const images: any = { horizontalBar, horizontalBarStacked, verticalBar, diff --git a/apps/leafcutter/components/Welcome.tsx b/apps/leafcutter/components/Welcome.tsx index b3fa0e9..7a4abe6 100644 --- a/apps/leafcutter/components/Welcome.tsx +++ b/apps/leafcutter/components/Welcome.tsx @@ -8,7 +8,7 @@ export const Welcome = () => { const { data: session } = useSession(); const { user: { name }, - } = session; + } = session as any; const { colors: { white, leafcutterElectricBlue }, typography: { h1, h4, p }, diff --git a/apps/leafcutter/lib/opensearch.ts b/apps/leafcutter/lib/opensearch.ts index 16f67dd..10985d0 100644 --- a/apps/leafcutter/lib/opensearch.ts +++ b/apps/leafcutter/lib/opensearch.ts @@ -103,7 +103,7 @@ export const getUserMetadata = async (username: string) => { } return res?.body._source; -} +}; export const saveUserMetadata = async (username: string, metadata: any) => { const client = createClient(); @@ -112,7 +112,7 @@ export const saveUserMetadata = async (username: string, metadata: any) => { index: userMetadataIndexName, body: { doc: { username, ...metadata } } }); -} +}; /* User */ @@ -130,13 +130,13 @@ const getCurrentUserIndex = async (email: string) => { const indicesResponse = await client.indices.get({ index: `.kibana_*_${userIndexName}_1`, - }) + }); const currentUserIndex = Object.keys(indicesResponse.body)[0]; return currentUserIndex; -} +}; -const getIndexPattern = async (index: string) => { +const getIndexPattern: any = async (index: string) => { const client = createClient(); const query = { query: { @@ -335,6 +335,7 @@ export const performQuery = async (searchQuery: any, limit: number) => { if (searchQuery.relativeDate.values.length > 0) { searchQuery.relativeDate.values.forEach((value: string) => { + // @ts-expect-error body.query.bool.must.push({ range: { date: { @@ -347,6 +348,7 @@ export const performQuery = async (searchQuery: any, limit: number) => { if (searchQuery.startDate.values.length > 0) { searchQuery.startDate.values.forEach((value: string) => { + // @ts-expect-error body.query.bool.must.push({ range: { date: { @@ -359,6 +361,7 @@ export const performQuery = async (searchQuery: any, limit: number) => { if (searchQuery.endDate.values.length > 0) { searchQuery.endDate.values.forEach((value: string) => { + // @ts-expect-error body.query.bool.must.push({ range: { date: { @@ -370,54 +373,63 @@ export const performQuery = async (searchQuery: any, limit: number) => { } if (searchQuery.incidentType.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "incident.keyword": searchQuery.incidentType.values }, }); } if (searchQuery.targetedGroup.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "targeted_group.keyword": searchQuery.targetedGroup.values }, }); } if (searchQuery.platform.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "technology.keyword": searchQuery.platform.values }, }); } if (searchQuery.device.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "technology.keyword": searchQuery.device.values }, }); } if (searchQuery.service.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "technology.keyword": searchQuery.service.values }, }); } if (searchQuery.maker.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "technology.keyword": searchQuery.maker.values }, }); } if (searchQuery.subregion.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "region.keyword": searchQuery.subregion.values }, }); } if (searchQuery.country.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "country.keyword": searchQuery.country.values }, }); } if (searchQuery.continent.values.length > 0) { + // @ts-expect-error body.query.bool.must.push({ terms: { "continent.keyword": searchQuery.continent.values }, }); diff --git a/apps/leafcutter/package.json b/apps/leafcutter/package.json index 5aff75e..2dec737 100644 --- a/apps/leafcutter/package.json +++ b/apps/leafcutter/package.json @@ -13,51 +13,50 @@ "lint": "next lint" }, "dependencies": { - "@emotion/cache": "^11.10.3", - "@emotion/react": "^11.10.4", - "@emotion/server": "^11.10.0", - "@emotion/styled": "^11.10.4", - "@fontsource/playfair-display": "^4.5.12", - "@fontsource/poppins": "^4.5.10", - "@fontsource/roboto": "^4.5.8", + "@emotion/cache": "^11.11.0", + "@emotion/react": "^11.11.0", + "@emotion/server": "^11.11.0", + "@emotion/styled": "^11.11.0", + "@fontsource/playfair-display": "^5.0.1", + "@fontsource/poppins": "^5.0.1", + "@fontsource/roboto": "^5.0.1", "@mui/icons-material": "^5", - "@mui/lab": "^5.0.0-alpha.102", + "@mui/lab": "^5.0.0-alpha.131", "@mui/material": "^5", - "@mui/styles": "^5", - "@mui/x-data-grid-pro": "^5.17.5", - "@mui/x-date-pickers-pro": "^5.0.3", + "@mui/x-data-grid-pro": "^6.5.0", + "@mui/x-date-pickers-pro": "^6.5.0", "@opensearch-project/opensearch": "^2.0.0", - "date-fns": "^2.29.3", + "date-fns": "^2.30.0", "http-proxy-middleware": "^2.0.6", - "material-ui-popup-state": "^4.1.0", - "next": "^12.3", - "next-auth": "^4.12.2", - "next-http-proxy-middleware": "^1.2.4", - "nodemailer": "^6.8.0", - "react": "^17", + "material-ui-popup-state": "^5.0.8", + "next": "^13.4", + "next-auth": "^4.22.1", + "next-http-proxy-middleware": "^1.2.5", + "nodemailer": "^6.9.2", + "react": "^18", "react-cookie": "^4.1.1", "react-cookie-consent": "^8.0.1", - "react-dom": "^17", - "react-iframe": "^1.8.4", - "react-markdown": "^8.0.3", + "react-dom": "^18", + "react-iframe": "^1.8.5", + "react-markdown": "^8.0.7", "react-polyglot": "^0.7.2", - "sharp": "^0.31.3", - "swr": "^1.3.0", + "sharp": "^0.32.1", + "swr": "^2.1.5", "uuid": "^9.0.0" }, "devDependencies": { - "@babel/core": "^7.19.3", - "@types/react": "^17", - "@types/uuid": "^8.3.4", - "babel-loader": "^8.2.5", - "eslint": "^8.24.0", + "@babel/core": "^7.21.8", + "@types/react": "^18", + "@types/uuid": "^9.0.1", + "babel-loader": "^9.1.2", + "eslint": "^8.41.0", "eslint-config-airbnb": "^19.0.4", - "eslint-config-next": "^12.3.1", - "eslint-config-prettier": "^8.5.0", - "eslint-plugin-import": "^2.26.0", - "eslint-plugin-jsx-a11y": "^6.6.1", + "eslint-config-next": "^13.4.3", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jsx-a11y": "^6.7.1", "eslint-plugin-prettier": "^4.2.1", - "eslint-plugin-react": "^7.31.8", - "typescript": "^4.9.5" + "eslint-plugin-react": "^7.32.2", + "typescript": "^5.0.4" } } diff --git a/apps/leafcutter/pages/_app.tsx b/apps/leafcutter/pages/_app.tsx index 08965b2..0071367 100644 --- a/apps/leafcutter/pages/_app.tsx +++ b/apps/leafcutter/pages/_app.tsx @@ -22,13 +22,11 @@ import "@fontsource/playfair-display/900.css"; import "styles/global.css"; import { LicenseInfo } from "@mui/x-data-grid-pro"; -LicenseInfo.setLicenseKey( - "fd009c623acc055adb16370731be92e4T1JERVI6NDA3NTQsRVhQSVJZPTE2ODAyNTAwMTUwMDAsS0VZVkVSU0lPTj0x" -); +LicenseInfo.setLicenseKey(process.env.MUI_LICENSE_KEY ?? ""); const clientSideEmotionCache: any = createEmotionCache(); -const messages = { en, fr }; +const messages: any = { en, fr }; interface LeafcutterWebProps extends AppProps { // eslint-disable-next-line react/require-default-props @@ -36,7 +34,7 @@ interface LeafcutterWebProps extends AppProps { } const LeafcutterWeb = (props: LeafcutterWebProps) => { - const { locale } = useRouter(); + const { locale = "en" } = useRouter(); const { Component, emotionCache = clientSideEmotionCache, pageProps } = props; return ( diff --git a/apps/leafcutter/pages/api/auth/[...nextauth].ts b/apps/leafcutter/pages/api/auth/[...nextauth].ts index 98a3d15..0705c42 100644 --- a/apps/leafcutter/pages/api/auth/[...nextauth].ts +++ b/apps/leafcutter/pages/api/auth/[...nextauth].ts @@ -5,12 +5,12 @@ import Apple from "next-auth/providers/apple"; export default NextAuth({ providers: [ Google({ - clientId: process.env.GOOGLE_CLIENT_ID, - clientSecret: process.env.GOOGLE_CLIENT_SECRET, + clientId: process.env.GOOGLE_CLIENT_ID ?? "", + clientSecret: process.env.GOOGLE_CLIENT_SECRET ?? "", }), Apple({ - clientId: process.env.APPLE_CLIENT_ID, - clientSecret: process.env.APPLE_CLIENT_SECRET + clientId: process.env.APPLE_CLIENT_ID ?? "", + clientSecret: process.env.APPLE_CLIENT_SECRET ?? "", }), ], secret: process.env.NEXTAUTH_SECRET, diff --git a/apps/leafcutter/pages/api/proxy/[[...path]].ts b/apps/leafcutter/pages/api/proxy/[[...path]].ts index e5850ac..4956739 100644 --- a/apps/leafcutter/pages/api/proxy/[[...path]].ts +++ b/apps/leafcutter/pages/api/proxy/[[...path]].ts @@ -3,8 +3,8 @@ import { NextApiRequest, NextApiResponse } from "next"; import { getToken } from "next-auth/jwt"; const withAuthInfo = - (handler) => async (req: NextApiRequest, res: NextApiResponse) => { - const session = await getToken({ + (handler: any) => async (req: NextApiRequest, res: NextApiResponse) => { + const session: any = await getToken({ req, secret: process.env.NEXTAUTH_SECRET, }); diff --git a/apps/leafcutter/pages/api/searches/create.ts b/apps/leafcutter/pages/api/searches/create.ts index 91a0764..569c434 100644 --- a/apps/leafcutter/pages/api/searches/create.ts +++ b/apps/leafcutter/pages/api/searches/create.ts @@ -16,7 +16,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { return res.status(500).json({ message: "Only POST requests are allowed" }); } - const { email } = session; + const { email }: any = session; const { name, query } = JSON.parse(req.body); const result = await getUserMetadata(email); const { savedSearches } = result; @@ -24,8 +24,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { savedSearches: [...savedSearches, { name, query }] }); const { savedSearches: updatedSavedSearches } = await getUserMetadata(email); - return res.json(updatedSavedSearches) -} + return res.json(updatedSavedSearches); +}; export default handler; diff --git a/apps/leafcutter/pages/api/searches/delete.ts b/apps/leafcutter/pages/api/searches/delete.ts index e7038e4..61108bd 100644 --- a/apps/leafcutter/pages/api/searches/delete.ts +++ b/apps/leafcutter/pages/api/searches/delete.ts @@ -16,14 +16,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { return res.status(500).json({ message: "Only POST requests are allowed" }); } - const { email } = session; + const { email }: any = session; const { name } = JSON.parse(req.body); const { savedSearches } = await getUserMetadata(email); - const updatedSavedSearches = savedSearches.filter(search => search.name !== name); - const result = await saveUserMetadata(email, { savedSearches: updatedSavedSearches }) + const updatedSavedSearches = savedSearches.filter((search: any) => search.name !== name); + const result = await saveUserMetadata(email, { savedSearches: updatedSavedSearches }); - return res.json({ result }) -} + return res.json({ result }); +}; export default handler; diff --git a/apps/leafcutter/pages/api/searches/list.ts b/apps/leafcutter/pages/api/searches/list.ts index 19024c4..1e0fc77 100644 --- a/apps/leafcutter/pages/api/searches/list.ts +++ b/apps/leafcutter/pages/api/searches/list.ts @@ -16,10 +16,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { return res.status(500).json({ message: "Only GET requests are allowed" }); } - const { email } = session; + const { email }: any = session; const { savedSearches } = await getUserMetadata(email); - return res.json(savedSearches) -} + return res.json(savedSearches); +}; export default handler; diff --git a/apps/leafcutter/pages/api/upload/index.ts b/apps/leafcutter/pages/api/upload/index.ts index 63ced67..73afd1f 100644 --- a/apps/leafcutter/pages/api/upload/index.ts +++ b/apps/leafcutter/pages/api/upload/index.ts @@ -25,13 +25,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const { id } = ticket; try { const country = ticket.country[0] ?? "none"; + // @ts-expect-error const translatedCountry = taxonomy.country[country]?.display ?? "none"; - const countryDetails = unRegions.find((c) => c.name === translatedCountry); + const countryDetails: any = unRegions.find((c) => c.name === translatedCountry); const augmentedTicket = { ...ticket, region: countryDetails['sub-region']?.toLowerCase().replace(" ", "-") ?? null, continent: countryDetails.region?.toLowerCase().replace(" ", "-") ?? null, - } + }; const out = await client.create({ id: uuid(), index: "sample_tagged_tickets", @@ -41,13 +42,13 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { console.log(out); succeeded.push(id); } catch (e) { - console.log(e) + console.log(e); failed.push(id); } } const results = { succeeded, failed }; - return res.json(results) + return res.json(results); }; export default handler; diff --git a/apps/leafcutter/pages/api/visualizations/create.ts b/apps/leafcutter/pages/api/visualizations/create.ts index 5e4a419..7759746 100644 --- a/apps/leafcutter/pages/api/visualizations/create.ts +++ b/apps/leafcutter/pages/api/visualizations/create.ts @@ -18,14 +18,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const { visualizationID, title, description, query } = req.body; const id = await createUserVisualization({ - email: session.email, + email: session.email as string, visualizationID, title, description, query }); - return res.json({ id }) + return res.json({ id }); }; export default handler; diff --git a/apps/leafcutter/pages/api/visualizations/delete.ts b/apps/leafcutter/pages/api/visualizations/delete.ts index 687c7a6..96a755d 100644 --- a/apps/leafcutter/pages/api/visualizations/delete.ts +++ b/apps/leafcutter/pages/api/visualizations/delete.ts @@ -17,9 +17,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { } const { id } = req.body; - await deleteUserVisualization(session.email, id); + await deleteUserVisualization(session.email as string, id); - return res.json({ id }) + return res.json({ id }); }; export default handler; diff --git a/apps/leafcutter/pages/api/visualizations/update.ts b/apps/leafcutter/pages/api/visualizations/update.ts index 8bc8762..b6d77d1 100644 --- a/apps/leafcutter/pages/api/visualizations/update.ts +++ b/apps/leafcutter/pages/api/visualizations/update.ts @@ -18,14 +18,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => { const { id, title, description, query } = req.body; await updateUserVisualization({ - email: session.email, + email: session.email as string, id, title, description, query }); - return res.json({ id }) + return res.json({ id }); }; export default handler; diff --git a/apps/leafcutter/pages/create.tsx b/apps/leafcutter/pages/create.tsx index d05543b..4fb28d8 100644 --- a/apps/leafcutter/pages/create.tsx +++ b/apps/leafcutter/pages/create.tsx @@ -1,4 +1,4 @@ -import { useEffect } from "react"; +import { FC, useEffect } from "react"; import { GetServerSideProps, GetServerSidePropsContext } from "next"; import Head from "next/head"; import { useTranslate } from "react-polyglot"; @@ -12,7 +12,11 @@ import { useAppContext } from "components/AppProvider"; import { PageHeader } from "components/PageHeader"; import { VisualizationBuilder } from "components/VisualizationBuilder"; -const Create = ({ templates }) => { +type CreateProps = { + templates: any; +}; + +const Create: FC = ({ templates }) => { const t = useTranslate(); const { colors: { cdrLinkOrange }, diff --git a/apps/leafcutter/pages/index.tsx b/apps/leafcutter/pages/index.tsx index c46eeea..c316f6b 100644 --- a/apps/leafcutter/pages/index.tsx +++ b/apps/leafcutter/pages/index.tsx @@ -1,5 +1,5 @@ import { useEffect } from "react"; -import { GetServerSideProps, GetServerSidePropsContext } from "next"; +import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next"; import { useRouter } from "next/router"; import Head from "next/head"; import Link from "next/link"; @@ -15,7 +15,13 @@ import { WelcomeDialog } from "components/WelcomeDialog"; import { VisualizationCard } from "components/VisualizationCard"; import { useAppContext } from "components/AppProvider"; -const MyVisualizations = ({ visualizations }) => { +type MyVisualizationsProps = { + visualizations: any; +}; + +const MyVisualizations: NextPage = ({ + visualizations, +}) => { const router = useRouter(); const cookieName = "homeIntroComplete"; const [cookies, setCookie] = useCookies([cookieName]); @@ -85,7 +91,7 @@ const MyVisualizations = ({ visualizations }) => { ) : null} - {visualizations.map((visualization, index) => ( + {visualizations.map((visualization: any, index: number) => ( { +type LoginProps = { + session: any; +}; + +const Login: NextPage = ({ session }) => { const t = useTranslate(); const { colors: { leafcutterElectricBlue, lightGray }, @@ -112,7 +117,7 @@ const Login = ({ session }) => { export default Login; -export async function getServerSideProps(context) { +export async function getServerSideProps(context: any) { const session = (await getSession(context)) ?? null; return { diff --git a/apps/leafcutter/pages/setup.tsx b/apps/leafcutter/pages/setup.tsx index fdeb8bb..aef1aca 100644 --- a/apps/leafcutter/pages/setup.tsx +++ b/apps/leafcutter/pages/setup.tsx @@ -1,10 +1,12 @@ -import { FC, useLayoutEffect } from "react"; +import { useLayoutEffect } from "react"; +import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next"; import { useRouter } from "next/router"; import { Grid, CircularProgress } from "@mui/material"; import Iframe from "react-iframe"; import { useAppContext } from "components/AppProvider"; +import { checkAuth } from "lib/checkAuth"; -export const Setup: FC = () => { +const Setup: NextPage = () => { const { colors: { leafcutterElectricBlue }, } = useAppContext(); @@ -44,3 +46,7 @@ export const Setup: FC = () => { }; export default Setup; + +export const getServerSideProps: GetServerSideProps = async ( + context: GetServerSidePropsContext +) => checkAuth(context); diff --git a/apps/leafcutter/pages/trends.tsx b/apps/leafcutter/pages/trends.tsx index 65ceb5b..e3d269c 100644 --- a/apps/leafcutter/pages/trends.tsx +++ b/apps/leafcutter/pages/trends.tsx @@ -1,4 +1,4 @@ -import { GetServerSideProps, GetServerSidePropsContext } from "next"; +import { NextPage, GetServerSideProps, GetServerSidePropsContext } from "next"; import Head from "next/head"; import { Grid, Box } from "@mui/material"; import { useTranslate } from "react-polyglot"; @@ -9,7 +9,11 @@ import { PageHeader } from "components/PageHeader"; import { VisualizationCard } from "components/VisualizationCard"; import { useAppContext } from "components/AppProvider"; -const Trends = ({ visualizations }) => { +type TrendsProps = { + visualizations: any; +}; + +const Trends: NextPage = ({ visualizations }) => { const t = useTranslate(); const { colors: { cdrLinkOrange }, @@ -58,7 +62,7 @@ const Trends = ({ visualizations }) => { spacing={3} justifyContent="space-between" > - {visualizations.map((visualization, index) => ( + {visualizations.map((visualization: any, index: number) => ( ( +type VisualizationProps = { + visualization: any; +}; + +const Visualization: NextPage = ({ visualization }) => ( Digital Threat Dashboard – Leafcutter @@ -43,7 +47,8 @@ export const getServerSideProps: GetServerSideProps = async ( const response = rawResponse.body; const hits = response.hits.hits.filter( - (hit) => hit._id.split(":")[1] === visualizationID[0] + // @ts-expect-error + (hit: any) => hit._id.split(":")[1] === visualizationID[0] ); const hit = hits[0]; res.props.visualization = { diff --git a/apps/leafcutter/tsconfig.json b/apps/leafcutter/tsconfig.json index f3d6b99..cdde52e 100644 --- a/apps/leafcutter/tsconfig.json +++ b/apps/leafcutter/tsconfig.json @@ -4,7 +4,7 @@ "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, - "strict": false, + "strict": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true, diff --git a/apps/link/components/InternalZammadWrapper.tsx b/apps/link/components/InternalZammadWrapper.tsx new file mode 100644 index 0000000..faef7df --- /dev/null +++ b/apps/link/components/InternalZammadWrapper.tsx @@ -0,0 +1,76 @@ +import { FC, useState } from "react"; +import { useRouter } from "next/router"; +import Iframe from "react-iframe"; + +type InternalZammadWrapperProps = { + path: string; + hideSidebar?: boolean; +}; + +export const InternalZammadWrapper: FC = ({ + path, + hideSidebar = true, +}) => { + const router = useRouter(); + const [display, setDisplay] = useState("none"); + const url = `${origin}/zammad${path}`; + console.log({ origin, path, url }); + + return ( + // @ts-ignore +