diff --git a/.eslintrc.json b/.eslintrc.json index 2ace00f9b..330186b8f 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -91,10 +91,11 @@ "alwaysTryTypes": true }, "node": { + "paths": ["src"], "extensions": [".js", ".jsx", ".ts", ".tsx"] }, "alias": [ - ["@root", "./"], + ["@root", "."], ["@classes", "./classes"], ["@errors", "./errors"], ["@logger", "./logger"], diff --git a/.gitignore b/.gitignore index 3ebb61157..c85e4bf58 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules/ build/ *.pem .env* -.idea/ \ No newline at end of file +.idea/ +.DS_Store \ No newline at end of file diff --git a/.sequelizerc b/.sequelizerc index 3a7b8492b..56fe81421 100644 --- a/.sequelizerc +++ b/.sequelizerc @@ -1,8 +1,8 @@ const path = require("path") module.exports = { - config: path.resolve("./database", "config.js"), - "models-path": path.resolve("./database", "models"), - "seeders-path": path.resolve("./database", "seeders"), - "migrations-path": path.resolve("./database", "migrations"), + config: path.resolve("src", "database", "config.js"), + "models-path": path.resolve("src", "database", "models"), + "seeders-path": path.resolve("src", "database", "seeders"), + "migrations-path": path.resolve("src", "database", "migrations"), } diff --git a/jest.config.js b/jest.config.js index f7f126c06..44c385eeb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -2,6 +2,7 @@ module.exports = { preset: "ts-jest", testEnvironment: "node", + rootDir: "src", moduleNameMapper: { "^@root/(.*)": "/$1", "^@classes/(.*)": "/classes/$1", diff --git a/middleware/auth.js b/middleware/auth.js deleted file mode 100644 index f9cfbfab8..000000000 --- a/middleware/auth.js +++ /dev/null @@ -1,489 +0,0 @@ -// Imports -const express = require("express") - -// Import logger -const logger = require("@logger/logger") - -// Import errors -const { AuthError } = require("@errors/AuthError") -const { NotFoundError } = require("@errors/NotFoundError") - -const jwtUtils = require("@utils/jwt-utils") - -// Import services -const { BadRequestError } = require("@root/errors/BadRequestError") -const identityServices = require("@services/identity") - -// Instantiate router object -const auth = express.Router() - -const { E2E_TEST_REPO, E2E_TEST_SECRET, E2E_TEST_GH_TOKEN } = process.env -const E2E_TEST_USER = "e2e-test" -const GENERAL_ACCESS_PATHS = ["/v1/sites", "/v1/auth/whoami"] - -function noVerify(req, res, next) { - next("router") -} - -function verifyE2E(req) { - const { isomercmsE2E } = req.cookies - const urlTokens = req.url.split("/") // urls take the form "/v1/sites//"" - let isValidE2E - - if (isomercmsE2E) { - if (isomercmsE2E !== E2E_TEST_SECRET) throw new AuthError("Bad credentials") - - // Throw an error if accessing a repo other than e2e-test-repo - // Otherwise, allow access only to paths available to all users - if (!GENERAL_ACCESS_PATHS.includes(req.url)) { - if (urlTokens.length >= 3) { - const repo = urlTokens[3] - if (repo !== E2E_TEST_REPO) - throw new AuthError( - `E2E tests can only access the ${E2E_TEST_REPO} repo` - ) - } else { - throw new BadRequestError("Invalid path") - } - } - - isValidE2E = true - } - - return isValidE2E -} - -const verifyJwt = (req, res, next) => { - const { isomercms } = req.cookies - const isValidE2E = verifyE2E(req) - - if (isValidE2E) { - res.locals.accessToken = E2E_TEST_GH_TOKEN - res.locals.userId = E2E_TEST_USER - } else { - try { - const { - access_token: retrievedToken, - user_id: retrievedId, - isomer_user_id: isomerUserId, - } = jwtUtils.verifyToken(isomercms) - - if (!isomerUserId) { - const notLoggedInError = new Error("User not logged in with email") - notLoggedInError.name = "NotLoggedInError" - throw notLoggedInError - } - - res.locals.accessToken = jwtUtils.decryptToken(retrievedToken) - res.locals.userId = retrievedId - } catch (err) { - logger.error("Authentication error") - if (err.name === "NotLoggedInError") { - throw new AuthError(err.message) - } - if (err.name === "TokenExpiredError") { - throw new AuthError("JWT token has expired") - } - } - } - - return next() -} - -// Extracts access_token if any, else set access_token to null -const whoamiAuth = (req, res, next) => { - const isValidE2E = verifyE2E(req) - - if (isValidE2E) { - res.locals.accessToken = E2E_TEST_GH_TOKEN - res.locals.userId = E2E_TEST_USER - } else { - let retrievedToken - try { - const { isomercms } = req.cookies - const { access_token: verifiedToken } = jwtUtils.verifyToken(isomercms) - if (!verifiedToken) throw new Error("Invalid token") - retrievedToken = jwtUtils.decryptToken(verifiedToken) - } catch (err) { - retrievedToken = undefined - } finally { - res.locals.accessToken = retrievedToken - } - } - - return next("router") -} - -// Replace access token with site access token if it is available -const useSiteAccessTokenIfAvailable = async (req, res, next) => { - const { authService, sitesService } = identityServices - const { userId, accessToken: userAccessToken } = res.locals - const { siteName } = req.params - - // Check if site is onboarded to Isomer identity, otherwise continue using user access token - const site = await sitesService.getBySiteName(siteName) - if (!site) { - logger.info( - `Site ${siteName} does not exists in site table. Default to using user access token.` - ) - return next() - } - - logger.info(`Verifying user's access to ${siteName}`) - if (!authService.hasAccessToSite(siteName, userId, userAccessToken)) { - throw new NotFoundError("Site does not exist") - } - - const siteAccessToken = await sitesService.getSiteAccessToken(siteName) - - if (siteAccessToken) { - res.locals.accessToken = siteAccessToken - logger.info( - `User ${userId} has access to ${siteName}. Using site access token ${site.apiTokenName}.` - ) - } - - return next() -} - -// Health check -auth.get("/v2/ping", noVerify) - -// Login and logout -auth.get("/v1/auth", noVerify) -auth.get("/v1/auth/github-redirect", noVerify) -auth.delete("/v1/auth/logout", noVerify) -auth.get("/v1/auth/whoami", whoamiAuth) - -// Index -auth.get("/v1", noVerify) - -// Inject site access token if available -auth.use("/v1/sites/:siteName", verifyJwt, useSiteAccessTokenIfAvailable) - -// Homepage -auth.get("/v1/sites/:siteName/homepage", verifyJwt) -auth.post("/v1/sites/:siteName/homepage", verifyJwt) - -// Directory -auth.get("/v1/sites/:siteName/files/:path", verifyJwt) - -// Folder pages -auth.get("/v1/sites/:siteName/folders/all", verifyJwt) -auth.delete( - "/v1/sites/:siteName/folders/:folderName/subfolder/:subfolderName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/folders/:folderName/subfolder/:subfolderName/rename/:newSubfolderName", - verifyJwt -) - -// Collection pages -auth.get("/v1/sites/:siteName/collections/:collectionName", verifyJwt) -auth.get("/v1/sites/:siteName/collections/:collectionName/pages", verifyJwt) -auth.post("/v1/sites/:siteName/collections/:collectionName/pages", verifyJwt) // to remove -auth.post( - "/v1/sites/:siteName/collections/:collectionName/pages/new/:pageName", - verifyJwt -) -auth.get( - "/v1/sites/:siteName/collections/:collectionName/pages/:pageName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/collections/:collectionName/pages/:pageName", - verifyJwt -) -auth.delete( - "/v1/sites/:siteName/collections/:collectionName/pages/:pageName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/collections/:collectionName/pages/:pageName/rename/:newPageName", - verifyJwt -) - -// Collections -auth.get("/v1/sites/:siteName/collections", verifyJwt) -auth.post("/v1/sites/:siteName/collections", verifyJwt) -auth.delete("/v1/sites/:siteName/collections/:collectionName", verifyJwt) -auth.post( - "/v1/sites/:siteName/collections/:collectionName/rename/:newCollectionName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/collections/:collectionPath/move/:targetPath", - verifyJwt -) - -// Documents -auth.get("/v1/sites/:siteName/documents", verifyJwt) -auth.post("/v1/sites/:siteName/documents", verifyJwt) -auth.get("/v1/sites/:siteName/documents/:documentName", verifyJwt) -auth.post("/v1/sites/:siteName/documents/:documentName", verifyJwt) -auth.delete("/v1/sites/:siteName/documents/:documentName", verifyJwt) -auth.post( - "/v1/sites/:siteName/documents/:documentName/rename/:newDocumentName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/documents/:documentName/move/:newDocumentName", - verifyJwt -) - -// Images -auth.get("/v1/sites/:siteName/images", verifyJwt) -auth.post("/v1/sites/:siteName/images", verifyJwt) -auth.get("/v1/sites/:siteName/images/:imageName", verifyJwt) -auth.post("/v1/sites/:siteName/images/:imageName", verifyJwt) -auth.delete("/v1/sites/:siteName/images/:imageName", verifyJwt) -auth.post( - "/v1/sites/:siteName/images/:imageName/rename/:newImageName", - verifyJwt -) -auth.post("/v1/sites/:siteName/images/:imageName/move/:newImageName", verifyJwt) - -// Media subfolders -auth.post("/v1/sites/:siteName/media/:mediaType/:folderPath", verifyJwt) -auth.delete("/v1/sites/:siteName/media/:mediaType/:folderPath", verifyJwt) -auth.post( - "/v1/sites/:siteName/media/:mediaType/:oldFolderPath/rename/:newFolderPath", - verifyJwt -) - -// Menu directory -auth.get("/v1/sites/:siteName/tree", verifyJwt) - -// Menu -auth.get("/v1/sites/:siteName/menus", verifyJwt) -auth.get("/v1/sites/:siteName/menus/:menuName", verifyJwt) -auth.post("/v1/sites/:siteName/menus/:menuName", verifyJwt) - -// Pages -auth.get("/v1/sites/:siteName/pages", verifyJwt) -auth.post("/v1/sites/:siteName/pages", verifyJwt) // to remove -auth.post("/v1/sites/:siteName/pages/new/:pageName", verifyJwt) -auth.get("/v1/sites/:siteName/pages/:pageName", verifyJwt) -auth.post("/v1/sites/:siteName/pages/:pageName", verifyJwt) -auth.delete("/v1/sites/:siteName/pages/:pageName", verifyJwt) -auth.post("/v1/sites/:siteName/pages/:pageName/rename/:newPageName", verifyJwt) -auth.post("/v1/sites/:siteName/pages/move/:newPagePath", verifyJwt) - -// Resource pages -auth.get("/v1/sites/:siteName/resources/:resourceName", verifyJwt) -auth.post("/v1/sites/:siteName/resources/:resourceName/pages", verifyJwt) -auth.get( - "/v1/sites/:siteName/resources/:resourceName/pages/:pageName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/resources/:resourceName/pages/new/:pageName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/resources/:resourceName/pages/:pageName", - verifyJwt -) -auth.delete( - "/v1/sites/:siteName/resources/:resourceName/pages/:pageName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/resources/:resourceName/pages/:pageName/rename/:newPageName", - verifyJwt -) - -// Resource room -auth.get("/v1/sites/:siteName/resource-room", verifyJwt) -auth.post("/v1/sites/:siteName/resource-room", verifyJwt) -auth.post("/v1/sites/:siteName/resource-room/:resourceRoom", verifyJwt) -auth.delete("/v1/sites/:siteName/resource-room", verifyJwt) - -// Resources -auth.get("/v1/sites/:siteName/resources", verifyJwt) -auth.post("/v1/sites/:siteName/resources", verifyJwt) -auth.delete("/v1/sites/:siteName/resources/:resourceName", verifyJwt) -auth.post( - "/v1/sites/:siteName/resources/:resourceName/rename/:newResourceName", - verifyJwt -) -auth.post( - "/v1/sites/:siteName/resources/:resourceName/move/:newResourceName", - verifyJwt -) - -// Settings -auth.get("/v1/sites/:siteName/settings", verifyJwt) -auth.post("/v1/sites/:siteName/settings", verifyJwt) - -// New settings -auth.get("/v2/sites/:siteName/settings", verifyJwt) -auth.post("/v2/sites/:siteName/settings", verifyJwt) - -// Navigation -auth.get("/v1/sites/:siteName/navigation", verifyJwt) -auth.post("/v1/sites/:siteName/navigation", verifyJwt) - -// Netlify toml -auth.get("/v1/sites/:siteName/netlify-toml", verifyJwt) - -// Sites -auth.get("/v1/sites", verifyJwt) -auth.get("/v1/sites/:siteName", verifyJwt) -auth.get("/v1/sites/:siteName/lastUpdated", verifyJwt) -auth.get("/v1/sites/:siteName/stagingUrl", verifyJwt) - -// Users -auth.post("/v1/user/email/otp", verifyJwt) -auth.post("/v1/user/email/verifyOtp", verifyJwt) -auth.post("/v1/user/mobile/otp", verifyJwt) -auth.post("/v1/user/mobile/verifyOtp", verifyJwt) - -// V2 Endpoints - -// Unlinked pages -auth.get("/v2/sites/:siteName/pages", verifyJwt) -auth.post("/v2/sites/:siteName/pages/pages", verifyJwt) -auth.get("/v2/sites/:siteName/pages/pages/:pageName", verifyJwt) -auth.post("/v2/sites/:siteName/pages/pages/:pageName", verifyJwt) -auth.delete("/v2/sites/:siteName/pages/pages/:pageName", verifyJwt) -auth.post("/v2/sites/:siteName/pages/move", verifyJwt) - -// Collection pages -auth.post("/v2/sites/:siteName/collections/:collectionName/pages", verifyJwt) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName/pages", - verifyJwt -) -auth.get( - "/v2/sites/:siteName/collections/:collectionName/pages/:pageName", - verifyJwt -) -auth.get( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName/pages/:pageName", - verifyJwt -) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/pages/:pageName", - verifyJwt -) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName/pages/:pageName", - verifyJwt -) -auth.delete( - "/v2/sites/:siteName/collections/:collectionName/pages/:pageName", - verifyJwt -) -auth.delete( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName/pages/:pageName", - verifyJwt -) - -// Resource Pages -auth.post( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName/pages", - verifyJwt -) -auth.get( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName/pages/:pageName", - verifyJwt -) -auth.post( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName/pages/:pageName", - verifyJwt -) -auth.delete( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName/pages/:pageName", - verifyJwt -) - -// Collections -auth.get("/v2/sites/:siteName/collections", verifyJwt) -auth.get("/v2/sites/:siteName/collections/:collectionName", verifyJwt) -auth.get( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName", - verifyJwt -) -auth.post("/v2/sites/:siteName/collections", verifyJwt) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/subcollections", - verifyJwt -) -auth.post("/v2/sites/:siteName/collections/:collectionName", verifyJwt) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName", - verifyJwt -) -auth.delete("/v2/sites/:siteName/collections/:collectionName", verifyJwt) -auth.delete( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName", - verifyJwt -) -auth.post("/v2/sites/:siteName/collections/:collectionName/reorder", verifyJwt) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName/reorder", - verifyJwt -) -auth.post("/v2/sites/:siteName/collections/:collectionName/move", verifyJwt) -auth.post( - "/v2/sites/:siteName/collections/:collectionName/subcollections/:subcollectionName/move", - verifyJwt -) - -// Resource Room -auth.get("/v2/sites/:siteName/resourceRoom", verifyJwt) -auth.post("/v2/sites/:siteName/resourceRoom", verifyJwt) -auth.get("/v2/sites/:siteName/resourceRoom/:resourceRoomName", verifyJwt) -auth.post("/v2/sites/:siteName/resourceRoom/:resourceRoomName", verifyJwt) -auth.delete("/v2/sites/:siteName/resourceRoom/:resourceRoomName", verifyJwt) - -// Resource Categories -auth.get( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName", - verifyJwt -) -auth.post( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources", - verifyJwt -) -auth.post( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName", - verifyJwt -) -auth.delete( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName", - verifyJwt -) -auth.post( - "/v2/sites/:siteName/resourceRoom/:resourceRoomName/resources/:resourceCategoryName/move", - verifyJwt -) - -// Media directories -auth.get("/v2/sites/:siteName/media/:directoryName", verifyJwt) -auth.post("/v2/sites/:siteName/media", verifyJwt) -auth.post("/v2/sites/:siteName/media/:directoryName", verifyJwt) -auth.delete("/v2/sites/:siteName/media/:directoryName", verifyJwt) -auth.post("/v2/sites/:siteName/media/:directoryName/move", verifyJwt) - -// Media files -auth.post("/v2/sites/:siteName/media/:directoryName/pages", verifyJwt) -auth.get("/v2/sites/:siteName/media/:directoryName/pages/:fileName", verifyJwt) -auth.post("/v2/sites/:siteName/media/:directoryName/pages/:fileName", verifyJwt) -auth.delete( - "/v2/sites/:siteName/media/:directoryName/pages/:fileName", - verifyJwt -) - -auth.use((req, res, next) => { - if (!req.route) { - return res.status(404).send("Unauthorised for unknown route") - } - return next() -}) - -module.exports = { - auth, -} diff --git a/package-lock.json b/package-lock.json index 1ae5e5ef9..2774dd70f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5660,7 +5660,7 @@ "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==", + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", "dev": true }, "content-disposition": { @@ -5959,7 +5959,7 @@ "delegates": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==", + "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", "dev": true }, "depd": { @@ -7695,7 +7695,7 @@ "has-unicode": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", + "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", "dev": true }, "helmet": { @@ -12214,7 +12214,7 @@ "set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, "setprototypeof": { diff --git a/package.json b/package.json index 695112267..9a9c91bee 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "build": "tsc -p tsconfig.build.json", "start": "node -r ts-node/register/transpile-only -r tsconfig-paths/register build/server.js", "dev:services": "docker compose up -d", - "dev": "source .env && ts-node-dev --respawn server.js", + "dev": "source .env && ts-node-dev --respawn src/server.js", "test": "source .env.test && jest", "release": "npm version $npm_config_isomer_update && git push --tags", "lint": "npx eslint .", @@ -117,19 +117,19 @@ } }, "_moduleAliases": { - "@root": ".", - "@classes": "classes", - "@errors": "errors", - "@logger": "logger", - "@middleware": "middleware", - "@routes": "routes", - "@utils": "utils", - "@loaders": "loaders", - "@database": "database", - "@services": "services", - "@validators": "validators", - "@fixtures": "fixtures", - "@constants": "constants" + "@root": "src", + "@classes": "src/classes", + "@errors": "src/errors", + "@logger": "src/logger", + "@middleware": "src/middleware", + "@routes": "src/routes", + "@utils": "src/utils", + "@loaders": "src/loaders", + "@database": "src/database", + "@services": "src/services", + "@validators": "src/validators", + "@fixtures": "src/fixtures", + "@constants": "src/constants" }, "lint-staged": { "**/*.(js|jsx|ts|tsx)": [ diff --git a/__mocks__/@aws-sdk/client-secrets-manager.ts b/src/__mocks__/@aws-sdk/client-secrets-manager.ts similarity index 100% rename from __mocks__/@aws-sdk/client-secrets-manager.ts rename to src/__mocks__/@aws-sdk/client-secrets-manager.ts diff --git a/__mocks__/axios.ts b/src/__mocks__/axios.ts similarity index 100% rename from __mocks__/axios.ts rename to src/__mocks__/axios.ts diff --git a/__mocks__/otplib.ts b/src/__mocks__/otplib.ts similarity index 100% rename from __mocks__/otplib.ts rename to src/__mocks__/otplib.ts diff --git a/bootstrap/index.ts b/src/bootstrap/index.ts similarity index 100% rename from bootstrap/index.ts rename to src/bootstrap/index.ts diff --git a/classes/Collection.js b/src/classes/Collection.js similarity index 100% rename from classes/Collection.js rename to src/classes/Collection.js diff --git a/classes/Config.js b/src/classes/Config.js similarity index 100% rename from classes/Config.js rename to src/classes/Config.js diff --git a/classes/Directory.js b/src/classes/Directory.js similarity index 100% rename from classes/Directory.js rename to src/classes/Directory.js diff --git a/classes/File.js b/src/classes/File.js similarity index 100% rename from classes/File.js rename to src/classes/File.js diff --git a/classes/MediaFile.js b/src/classes/MediaFile.js similarity index 100% rename from classes/MediaFile.js rename to src/classes/MediaFile.js diff --git a/classes/MediaSubfolder.js b/src/classes/MediaSubfolder.js similarity index 100% rename from classes/MediaSubfolder.js rename to src/classes/MediaSubfolder.js diff --git a/classes/NetlifyToml.js b/src/classes/NetlifyToml.js similarity index 100% rename from classes/NetlifyToml.js rename to src/classes/NetlifyToml.js diff --git a/classes/Resource.js b/src/classes/Resource.js similarity index 100% rename from classes/Resource.js rename to src/classes/Resource.js diff --git a/classes/ResourceRoom.js b/src/classes/ResourceRoom.js similarity index 100% rename from classes/ResourceRoom.js rename to src/classes/ResourceRoom.js diff --git a/classes/Settings.js b/src/classes/Settings.js similarity index 100% rename from classes/Settings.js rename to src/classes/Settings.js diff --git a/classes/Subfolder.js b/src/classes/Subfolder.js similarity index 100% rename from classes/Subfolder.js rename to src/classes/Subfolder.js diff --git a/constants/constants.ts b/src/constants/constants.ts similarity index 100% rename from constants/constants.ts rename to src/constants/constants.ts diff --git a/constants/index.ts b/src/constants/index.ts similarity index 100% rename from constants/index.ts rename to src/constants/index.ts diff --git a/database/config.js b/src/database/config.js similarity index 100% rename from database/config.js rename to src/database/config.js diff --git a/database/index.ts b/src/database/index.ts similarity index 100% rename from database/index.ts rename to src/database/index.ts diff --git a/database/migrations/20210708163619-create-users.js b/src/database/migrations/20210708163619-create-users.js similarity index 100% rename from database/migrations/20210708163619-create-users.js rename to src/database/migrations/20210708163619-create-users.js diff --git a/database/migrations/20210708163623-create-sites.js b/src/database/migrations/20210708163623-create-sites.js similarity index 100% rename from database/migrations/20210708163623-create-sites.js rename to src/database/migrations/20210708163623-create-sites.js diff --git a/database/migrations/20210708163632-create-site-members.js b/src/database/migrations/20210708163632-create-site-members.js similarity index 100% rename from database/migrations/20210708163632-create-site-members.js rename to src/database/migrations/20210708163632-create-site-members.js diff --git a/database/migrations/20220407074127-create-whitelist.js b/src/database/migrations/20220407074127-create-whitelist.js similarity index 100% rename from database/migrations/20220407074127-create-whitelist.js rename to src/database/migrations/20220407074127-create-whitelist.js diff --git a/database/migrations/20220510075239-create-access-tokens.js b/src/database/migrations/20220510075239-create-access-tokens.js similarity index 100% rename from database/migrations/20220510075239-create-access-tokens.js rename to src/database/migrations/20220510075239-create-access-tokens.js diff --git a/database/migrations/20220610074022-create-repo.js b/src/database/migrations/20220610074022-create-repo.js similarity index 100% rename from database/migrations/20220610074022-create-repo.js rename to src/database/migrations/20220610074022-create-repo.js diff --git a/database/migrations/20220610074035-create-deployment.js b/src/database/migrations/20220610074035-create-deployment.js similarity index 100% rename from database/migrations/20220610074035-create-deployment.js rename to src/database/migrations/20220610074035-create-deployment.js diff --git a/database/migrations/20220610074044-add-status-columns-to-sites.js b/src/database/migrations/20220610074044-add-status-columns-to-sites.js similarity index 100% rename from database/migrations/20220610074044-add-status-columns-to-sites.js rename to src/database/migrations/20220610074044-add-status-columns-to-sites.js diff --git a/database/migrations/20220610074055-associate-user-creator.js b/src/database/migrations/20220610074055-associate-user-creator.js similarity index 100% rename from database/migrations/20220610074055-associate-user-creator.js rename to src/database/migrations/20220610074055-associate-user-creator.js diff --git a/database/migrations/20220610074066-add-deleted-at-columns.js b/src/database/migrations/20220610074066-add-deleted-at-columns.js similarity index 100% rename from database/migrations/20220610074066-add-deleted-at-columns.js rename to src/database/migrations/20220610074066-add-deleted-at-columns.js diff --git a/database/migrations/20220630022156-add-hosting-id.js b/src/database/migrations/20220630022156-add-hosting-id.js similarity index 100% rename from database/migrations/20220630022156-add-hosting-id.js rename to src/database/migrations/20220630022156-add-hosting-id.js diff --git a/database/migrations/20220630070630-change-site-status.js b/src/database/migrations/20220630070630-change-site-status.js similarity index 100% rename from database/migrations/20220630070630-change-site-status.js rename to src/database/migrations/20220630070630-change-site-status.js diff --git a/database/models/AccessToken.ts b/src/database/models/AccessToken.ts similarity index 100% rename from database/models/AccessToken.ts rename to src/database/models/AccessToken.ts diff --git a/database/models/Deployment.ts b/src/database/models/Deployment.ts similarity index 100% rename from database/models/Deployment.ts rename to src/database/models/Deployment.ts diff --git a/database/models/Repo.ts b/src/database/models/Repo.ts similarity index 100% rename from database/models/Repo.ts rename to src/database/models/Repo.ts diff --git a/database/models/Site.ts b/src/database/models/Site.ts similarity index 100% rename from database/models/Site.ts rename to src/database/models/Site.ts diff --git a/database/models/SiteMember.ts b/src/database/models/SiteMember.ts similarity index 100% rename from database/models/SiteMember.ts rename to src/database/models/SiteMember.ts diff --git a/database/models/User.ts b/src/database/models/User.ts similarity index 100% rename from database/models/User.ts rename to src/database/models/User.ts diff --git a/database/models/Whitelist.ts b/src/database/models/Whitelist.ts similarity index 100% rename from database/models/Whitelist.ts rename to src/database/models/Whitelist.ts diff --git a/database/models/index.ts b/src/database/models/index.ts similarity index 100% rename from database/models/index.ts rename to src/database/models/index.ts diff --git a/errors/AuthError.js b/src/errors/AuthError.js similarity index 100% rename from errors/AuthError.js rename to src/errors/AuthError.js diff --git a/errors/BadRequestError.js b/src/errors/BadRequestError.js similarity index 100% rename from errors/BadRequestError.js rename to src/errors/BadRequestError.js diff --git a/errors/BaseError.js b/src/errors/BaseError.js similarity index 100% rename from errors/BaseError.js rename to src/errors/BaseError.js diff --git a/errors/ConflictError.js b/src/errors/ConflictError.js similarity index 100% rename from errors/ConflictError.js rename to src/errors/ConflictError.js diff --git a/errors/ForbiddenError.js b/src/errors/ForbiddenError.js similarity index 100% rename from errors/ForbiddenError.js rename to src/errors/ForbiddenError.js diff --git a/errors/InitializationError.ts b/src/errors/InitializationError.ts similarity index 100% rename from errors/InitializationError.ts rename to src/errors/InitializationError.ts diff --git a/errors/MediaTypeError.js b/src/errors/MediaTypeError.js similarity index 100% rename from errors/MediaTypeError.js rename to src/errors/MediaTypeError.js diff --git a/errors/NotFoundError.js b/src/errors/NotFoundError.js similarity index 100% rename from errors/NotFoundError.js rename to src/errors/NotFoundError.js diff --git a/errors/UnprocessableError.js b/src/errors/UnprocessableError.js similarity index 100% rename from errors/UnprocessableError.js rename to src/errors/UnprocessableError.js diff --git a/fixtures/app.js b/src/fixtures/app.js similarity index 100% rename from fixtures/app.js rename to src/fixtures/app.js diff --git a/fixtures/config.js b/src/fixtures/config.js similarity index 100% rename from fixtures/config.js rename to src/fixtures/config.js diff --git a/fixtures/contactUs.js b/src/fixtures/contactUs.js similarity index 100% rename from fixtures/contactUs.js rename to src/fixtures/contactUs.js diff --git a/fixtures/footer.js b/src/fixtures/footer.js similarity index 100% rename from fixtures/footer.js rename to src/fixtures/footer.js diff --git a/fixtures/homepage.js b/src/fixtures/homepage.js similarity index 100% rename from fixtures/homepage.js rename to src/fixtures/homepage.js diff --git a/fixtures/identity.ts b/src/fixtures/identity.ts similarity index 100% rename from fixtures/identity.ts rename to src/fixtures/identity.ts diff --git a/fixtures/navigation.js b/src/fixtures/navigation.js similarity index 100% rename from fixtures/navigation.js rename to src/fixtures/navigation.js diff --git a/fixtures/netlifyToml.js b/src/fixtures/netlifyToml.js similarity index 100% rename from fixtures/netlifyToml.js rename to src/fixtures/netlifyToml.js diff --git a/fixtures/repoInfo.js b/src/fixtures/repoInfo.js similarity index 100% rename from fixtures/repoInfo.js rename to src/fixtures/repoInfo.js diff --git a/global.d.ts b/src/global.d.ts similarity index 100% rename from global.d.ts rename to src/global.d.ts diff --git a/integration/Users.spec.ts b/src/integration/Users.spec.ts similarity index 99% rename from integration/Users.spec.ts rename to src/integration/Users.spec.ts index 8a50b1c45..4a0a0dca0 100644 --- a/integration/Users.spec.ts +++ b/src/integration/Users.spec.ts @@ -4,7 +4,7 @@ import request from "supertest" import { User, Whitelist } from "@database/models" import { generateRouter } from "@fixtures/app" -import { UsersRouter as _UsersRouter } from "@root/newroutes/authenticated/users" +import { UsersRouter as _UsersRouter } from "@root/routes/v2/authenticated/users" import { getUsersService } from "@services/identity" import { sequelize } from "@tests/database" diff --git a/logger/logger.js b/src/logger/logger.js similarity index 100% rename from logger/logger.js rename to src/logger/logger.js diff --git a/middleware/apiLogger.js b/src/middleware/apiLogger.js similarity index 100% rename from middleware/apiLogger.js rename to src/middleware/apiLogger.js diff --git a/newmiddleware/auth.js b/src/middleware/auth.js similarity index 100% rename from newmiddleware/auth.js rename to src/middleware/auth.js diff --git a/middleware/errorHandler.js b/src/middleware/errorHandler.js similarity index 100% rename from middleware/errorHandler.js rename to src/middleware/errorHandler.js diff --git a/newmiddleware/index.ts b/src/middleware/index.ts similarity index 92% rename from newmiddleware/index.ts rename to src/middleware/index.ts index f2d3e159a..68e44e20f 100644 --- a/newmiddleware/index.ts +++ b/src/middleware/index.ts @@ -1,9 +1,9 @@ import FormSG from "@opengovsg/formsg-sdk" import express, { RequestHandler } from "express" -import FormsProcessingService from "@root/services/middlewareServices/FormsProcessingService" import AuthService from "@services/identity/AuthService" import { AuthMiddlewareService } from "@services/middlewareServices/AuthMiddlewareService" +import FormsProcessingService from "@services/middlewareServices/FormsProcessingService" import { AuthMiddleware } from "./auth" diff --git a/middleware/routeHandler.js b/src/middleware/routeHandler.js similarity index 100% rename from middleware/routeHandler.js rename to src/middleware/routeHandler.js diff --git a/newroutes/formsgSiteCreation.ts b/src/routes/formsgSiteCreation.ts similarity index 97% rename from newroutes/formsgSiteCreation.ts rename to src/routes/formsgSiteCreation.ts index 6ff236485..4a9402179 100644 --- a/newroutes/formsgSiteCreation.ts +++ b/src/routes/formsgSiteCreation.ts @@ -9,10 +9,10 @@ import InitializationError from "@errors/InitializationError" import { getField } from "@utils/formsg-utils" -import { attachFormSGHandler } from "@root/newmiddleware" -import { mailer } from "@services/identity/MailClient" +import { attachFormSGHandler } from "@root/middleware" import UsersService from "@services/identity/UsersService" import InfraService from "@services/infra/InfraService" +import { mailer } from "@services/utilServices/MailClient" const { SITE_CREATE_FORM_KEY } = process.env const REQUESTER_EMAIL_FIELD = "Government E-mail" diff --git a/routes/auth.js b/src/routes/v1/auth.js similarity index 98% rename from routes/auth.js rename to src/routes/v1/auth.js index bec0ab06d..abe7e7601 100644 --- a/routes/auth.js +++ b/src/routes/v1/auth.js @@ -13,7 +13,7 @@ const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler") const validateStatus = require("@utils/axios-utils") const jwtUtils = require("@utils/jwt-utils") -const { authMiddleware } = require("@root/newmiddleware/index") +const { authMiddleware } = require("@root/middleware") // Import services const identityServices = require("@services/identity") diff --git a/routes/authenticated/index.js b/src/routes/v1/authenticated/index.js similarity index 79% rename from routes/authenticated/index.js rename to src/routes/v1/authenticated/index.js index 9b4d543e3..8701aa02e 100644 --- a/routes/authenticated/index.js +++ b/src/routes/v1/authenticated/index.js @@ -1,8 +1,7 @@ const express = require("express") -const sitesRouter = require("@root/routes/authenticated/sites") - -const { UsersRouter } = require("../../newroutes/authenticated/users") +const sitesRouter = require("@routes/v1/authenticated/sites") +const { UsersRouter } = require("@routes/v2/authenticated/users") const getAuthenticatedSubrouter = ({ authMiddleware, usersService }) => { // Workaround - no v1 users router exists diff --git a/routes/authenticated/sites.js b/src/routes/v1/authenticated/sites.js similarity index 99% rename from routes/authenticated/sites.js rename to src/routes/v1/authenticated/sites.js index 1fdef21c8..434995707 100644 --- a/routes/authenticated/sites.js +++ b/src/routes/v1/authenticated/sites.js @@ -9,7 +9,7 @@ const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler") const { genericGitHubAxiosInstance: axios, -} = require("@root/services/api/AxiosInstance") +} = require("@services/api/AxiosInstance") const router = express.Router() diff --git a/routes/authenticatedSites/collectionPages.js b/src/routes/v1/authenticatedSites/collectionPages.js similarity index 100% rename from routes/authenticatedSites/collectionPages.js rename to src/routes/v1/authenticatedSites/collectionPages.js diff --git a/routes/authenticatedSites/collections.js b/src/routes/v1/authenticatedSites/collections.js similarity index 98% rename from routes/authenticatedSites/collections.js rename to src/routes/v1/authenticatedSites/collections.js index 54a397f56..0f436809e 100644 --- a/routes/authenticatedSites/collections.js +++ b/src/routes/v1/authenticatedSites/collections.js @@ -8,8 +8,8 @@ const { } = require("@middleware/routeHandler") // Import classes -const { Collection } = require("@classes/Collection.js") -const { CollectionConfig } = require("@classes/Config.js") +const { Collection } = require("@classes/Collection") +const { CollectionConfig } = require("@classes/Config") const { File, CollectionPageType, PageType } = require("@classes/File") const { Subfolder } = require("@classes/Subfolder") diff --git a/routes/authenticatedSites/directory.js b/src/routes/v1/authenticatedSites/directory.js similarity index 93% rename from routes/authenticatedSites/directory.js rename to src/routes/v1/authenticatedSites/directory.js index ffcbf797f..73d1a3058 100644 --- a/routes/authenticatedSites/directory.js +++ b/src/routes/v1/authenticatedSites/directory.js @@ -5,7 +5,7 @@ const router = express.Router({ mergeParams: true }) // Import middleware const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler") -const { Directory, FolderType } = require("@classes/Directory.js") +const { Directory, FolderType } = require("@classes/Directory") // List pages and directories in folder async function listDirectoryContent(req, res) { diff --git a/routes/authenticatedSites/documents.js b/src/routes/v1/authenticatedSites/documents.js similarity index 98% rename from routes/authenticatedSites/documents.js rename to src/routes/v1/authenticatedSites/documents.js index 2e9d6be75..4cc88b567 100644 --- a/routes/authenticatedSites/documents.js +++ b/src/routes/v1/authenticatedSites/documents.js @@ -9,8 +9,8 @@ const { attachRollbackRouteHandlerWrapper, } = require("@middleware/routeHandler") -const { File, DocumentType } = require("@classes/File.js") -const { MediaFile } = require("@classes/MediaFile.js") +const { File, DocumentType } = require("@classes/File") +const { MediaFile } = require("@classes/MediaFile") const extractDirectoryAndFileName = (documentName) => { let documentDirectory diff --git a/routes/authenticatedSites/folders.js b/src/routes/v1/authenticatedSites/folders.js similarity index 98% rename from routes/authenticatedSites/folders.js rename to src/routes/v1/authenticatedSites/folders.js index 0a74ea9f0..e1f0b2000 100644 --- a/routes/authenticatedSites/folders.js +++ b/src/routes/v1/authenticatedSites/folders.js @@ -12,11 +12,7 @@ const { Collection } = require("@classes/Collection") const { CollectionConfig } = require("@classes/Config") const { File, CollectionPageType } = require("@classes/File") -const { - getTree, - sendTree, - deslugifyCollectionName, -} = require("@utils/utils.js") +const { getTree, sendTree, deslugifyCollectionName } = require("@utils/utils") const router = express.Router({ mergeParams: true }) diff --git a/routes/authenticatedSites/homepage.js b/src/routes/v1/authenticatedSites/homepage.js similarity index 96% rename from routes/authenticatedSites/homepage.js rename to src/routes/v1/authenticatedSites/homepage.js index fe0fd6abf..266f12713 100644 --- a/routes/authenticatedSites/homepage.js +++ b/src/routes/v1/authenticatedSites/homepage.js @@ -9,7 +9,7 @@ const { } = require("@middleware/routeHandler") // Import classes -const { File, HomepageType } = require("@classes/File.js") +const { File, HomepageType } = require("@classes/File") // Constants const HOMEPAGE_INDEX_PATH = "index.md" // Empty string diff --git a/routes/authenticatedSites/images.js b/src/routes/v1/authenticatedSites/images.js similarity index 100% rename from routes/authenticatedSites/images.js rename to src/routes/v1/authenticatedSites/images.js diff --git a/routes/authenticatedSites/index.js b/src/routes/v1/authenticatedSites/index.js similarity index 55% rename from routes/authenticatedSites/index.js rename to src/routes/v1/authenticatedSites/index.js index 956dacfc3..43eb1854b 100644 --- a/routes/authenticatedSites/index.js +++ b/src/routes/v1/authenticatedSites/index.js @@ -1,20 +1,20 @@ const express = require("express") -const collectionPagesRouter = require("@routes/authenticatedSites/collectionPages") -const collectionsRouter = require("@routes/authenticatedSites/collections") -const directoryRouter = require("@routes/authenticatedSites/directory") -const documentsRouter = require("@routes/authenticatedSites/documents") -const foldersRouter = require("@routes/authenticatedSites/folders") -const homepageRouter = require("@routes/authenticatedSites/homepage") -const imagesRouter = require("@routes/authenticatedSites/images") -const mediaSubfolderRouter = require("@routes/authenticatedSites/mediaSubfolder") -const navigationRouter = require("@routes/authenticatedSites/navigation") -const netlifyTomlRouter = require("@routes/authenticatedSites/netlifyToml") -const pagesRouter = require("@routes/authenticatedSites/pages") -const resourcePagesRouter = require("@routes/authenticatedSites/resourcePages") -const resourceRoomRouter = require("@routes/authenticatedSites/resourceRoom") -const resourcesRouter = require("@routes/authenticatedSites/resources") -const settingsRouter = require("@routes/authenticatedSites/settings") +const collectionPagesRouter = require("@routes/v1/authenticatedSites/collectionPages") +const collectionsRouter = require("@routes/v1/authenticatedSites/collections") +const directoryRouter = require("@routes/v1/authenticatedSites/directory") +const documentsRouter = require("@routes/v1/authenticatedSites/documents") +const foldersRouter = require("@routes/v1/authenticatedSites/folders") +const homepageRouter = require("@routes/v1/authenticatedSites/homepage") +const imagesRouter = require("@routes/v1/authenticatedSites/images") +const mediaSubfolderRouter = require("@routes/v1/authenticatedSites/mediaSubfolder") +const navigationRouter = require("@routes/v1/authenticatedSites/navigation") +const netlifyTomlRouter = require("@routes/v1/authenticatedSites/netlifyToml") +const pagesRouter = require("@routes/v1/authenticatedSites/pages") +const resourcePagesRouter = require("@routes/v1/authenticatedSites/resourcePages") +const resourceRoomRouter = require("@routes/v1/authenticatedSites/resourceRoom") +const resourcesRouter = require("@routes/v1/authenticatedSites/resources") +const settingsRouter = require("@routes/v1/authenticatedSites/settings") const getAuthenticatedSitesSubrouter = ({ authMiddleware }) => { const authenticatedSitesSubrouter = express.Router({ mergeParams: true }) diff --git a/routes/authenticatedSites/mediaSubfolder.js b/src/routes/v1/authenticatedSites/mediaSubfolder.js similarity index 100% rename from routes/authenticatedSites/mediaSubfolder.js rename to src/routes/v1/authenticatedSites/mediaSubfolder.js diff --git a/routes/authenticatedSites/navigation.js b/src/routes/v1/authenticatedSites/navigation.js similarity index 95% rename from routes/authenticatedSites/navigation.js rename to src/routes/v1/authenticatedSites/navigation.js index 7058f170a..9cae08a8f 100644 --- a/routes/authenticatedSites/navigation.js +++ b/src/routes/v1/authenticatedSites/navigation.js @@ -10,7 +10,7 @@ const { } = require("@middleware/routeHandler") // Import Classes -const { File, DataType } = require("@classes/File.js") +const { File, DataType } = require("@classes/File") const NAVIGATION_PATH = "navigation.yml" diff --git a/routes/authenticatedSites/netlifyToml.js b/src/routes/v1/authenticatedSites/netlifyToml.js similarity index 100% rename from routes/authenticatedSites/netlifyToml.js rename to src/routes/v1/authenticatedSites/netlifyToml.js diff --git a/routes/authenticatedSites/pages.js b/src/routes/v1/authenticatedSites/pages.js similarity index 99% rename from routes/authenticatedSites/pages.js rename to src/routes/v1/authenticatedSites/pages.js index b2b241450..cde5de760 100644 --- a/routes/authenticatedSites/pages.js +++ b/src/routes/v1/authenticatedSites/pages.js @@ -9,9 +9,9 @@ const { } = require("@middleware/routeHandler") // Import classes -const { Collection } = require("@classes/Collection.js") +const { Collection } = require("@classes/Collection") const { CollectionConfig } = require("@classes/Config") -const { File, PageType, CollectionPageType } = require("@classes/File.js") +const { File, PageType, CollectionPageType } = require("@classes/File") const { Subfolder } = require("@classes/Subfolder") const { deslugifyCollectionName } = require("@utils/utils") diff --git a/routes/authenticatedSites/resourcePages.js b/src/routes/v1/authenticatedSites/resourcePages.js similarity index 97% rename from routes/authenticatedSites/resourcePages.js rename to src/routes/v1/authenticatedSites/resourcePages.js index ad7227af5..4b3f56f3f 100644 --- a/routes/authenticatedSites/resourcePages.js +++ b/src/routes/v1/authenticatedSites/resourcePages.js @@ -12,9 +12,9 @@ const { } = require("@middleware/routeHandler") // Import classes -const { File, ResourcePageType } = require("@classes/File.js") -const { Resource } = require("@classes/Resource.js") -const { ResourceRoom } = require("@classes/ResourceRoom.js") +const { File, ResourcePageType } = require("@classes/File") +const { Resource } = require("@classes/Resource") +const { ResourceRoom } = require("@classes/ResourceRoom") // List pages in resource async function listResourcePages(req, res) { diff --git a/routes/authenticatedSites/resourceRoom.js b/src/routes/v1/authenticatedSites/resourceRoom.js similarity index 96% rename from routes/authenticatedSites/resourceRoom.js rename to src/routes/v1/authenticatedSites/resourceRoom.js index cd23edb7e..f0fae0ba6 100644 --- a/routes/authenticatedSites/resourceRoom.js +++ b/src/routes/v1/authenticatedSites/resourceRoom.js @@ -8,7 +8,7 @@ const { attachRollbackRouteHandlerWrapper, } = require("@middleware/routeHandler") -const { ResourceRoom } = require("@classes/ResourceRoom.js") +const { ResourceRoom } = require("@classes/ResourceRoom") // Get resource room name async function getResourceRoomName(req, res) { diff --git a/routes/authenticatedSites/resources.js b/src/routes/v1/authenticatedSites/resources.js similarity index 100% rename from routes/authenticatedSites/resources.js rename to src/routes/v1/authenticatedSites/resources.js diff --git a/routes/authenticatedSites/settings.js b/src/routes/v1/authenticatedSites/settings.js similarity index 94% rename from routes/authenticatedSites/settings.js rename to src/routes/v1/authenticatedSites/settings.js index b7fdf83f9..ae28cda35 100644 --- a/routes/authenticatedSites/settings.js +++ b/src/routes/v1/authenticatedSites/settings.js @@ -9,7 +9,7 @@ const { } = require("@middleware/routeHandler") // Import Classes -const { Settings } = require("@classes/Settings.js") +const { Settings } = require("@classes/Settings") async function getSettings(req, res) { const { accessToken } = res.locals diff --git a/newroutes/__tests__/Auth.spec.js b/src/routes/v2/__tests__/Auth.spec.js similarity index 100% rename from newroutes/__tests__/Auth.spec.js rename to src/routes/v2/__tests__/Auth.spec.js diff --git a/newroutes/auth.js b/src/routes/v2/auth.js similarity index 100% rename from newroutes/auth.js rename to src/routes/v2/auth.js diff --git a/newroutes/authenticated/__tests__/NetlifyToml.spec.js b/src/routes/v2/authenticated/__tests__/NetlifyToml.spec.js similarity index 100% rename from newroutes/authenticated/__tests__/NetlifyToml.spec.js rename to src/routes/v2/authenticated/__tests__/NetlifyToml.spec.js diff --git a/newroutes/authenticated/__tests__/Sites.spec.js b/src/routes/v2/authenticated/__tests__/Sites.spec.js similarity index 100% rename from newroutes/authenticated/__tests__/Sites.spec.js rename to src/routes/v2/authenticated/__tests__/Sites.spec.js diff --git a/newroutes/authenticated/index.js b/src/routes/v2/authenticated/index.js similarity index 100% rename from newroutes/authenticated/index.js rename to src/routes/v2/authenticated/index.js diff --git a/newroutes/authenticated/netlifyToml.js b/src/routes/v2/authenticated/netlifyToml.js similarity index 100% rename from newroutes/authenticated/netlifyToml.js rename to src/routes/v2/authenticated/netlifyToml.js diff --git a/newroutes/authenticated/sites.js b/src/routes/v2/authenticated/sites.js similarity index 100% rename from newroutes/authenticated/sites.js rename to src/routes/v2/authenticated/sites.js diff --git a/newroutes/authenticated/users.ts b/src/routes/v2/authenticated/users.ts similarity index 100% rename from newroutes/authenticated/users.ts rename to src/routes/v2/authenticated/users.ts diff --git a/newroutes/authenticatedSites/__tests__/CollectionPages.spec.js b/src/routes/v2/authenticatedSites/__tests__/CollectionPages.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/CollectionPages.spec.js rename to src/routes/v2/authenticatedSites/__tests__/CollectionPages.spec.js diff --git a/newroutes/authenticatedSites/__tests__/Collections.spec.js b/src/routes/v2/authenticatedSites/__tests__/Collections.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/Collections.spec.js rename to src/routes/v2/authenticatedSites/__tests__/Collections.spec.js diff --git a/newroutes/authenticatedSites/__tests__/ContactUs.spec.js b/src/routes/v2/authenticatedSites/__tests__/ContactUs.spec.js similarity index 98% rename from newroutes/authenticatedSites/__tests__/ContactUs.spec.js rename to src/routes/v2/authenticatedSites/__tests__/ContactUs.spec.js index b34d999a6..5ee9444a7 100644 --- a/newroutes/authenticatedSites/__tests__/ContactUs.spec.js +++ b/src/routes/v2/authenticatedSites/__tests__/ContactUs.spec.js @@ -4,8 +4,8 @@ const request = require("supertest") const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler") +const { generateRouter } = require("@fixtures/app") const { contactUsContent, contactUsSha } = require("@fixtures/contactUs") -const { generateRouter } = require("@root/fixtures/app") const { ContactUsRouter } = require("../contactUs") diff --git a/newroutes/authenticatedSites/__tests__/Homepage.spec.js b/src/routes/v2/authenticatedSites/__tests__/Homepage.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/Homepage.spec.js rename to src/routes/v2/authenticatedSites/__tests__/Homepage.spec.js diff --git a/newroutes/authenticatedSites/__tests__/MediaCategories.spec.js b/src/routes/v2/authenticatedSites/__tests__/MediaCategories.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/MediaCategories.spec.js rename to src/routes/v2/authenticatedSites/__tests__/MediaCategories.spec.js diff --git a/newroutes/authenticatedSites/__tests__/MediaFiles.spec.js b/src/routes/v2/authenticatedSites/__tests__/MediaFiles.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/MediaFiles.spec.js rename to src/routes/v2/authenticatedSites/__tests__/MediaFiles.spec.js diff --git a/newroutes/authenticatedSites/__tests__/Navigation.spec.js b/src/routes/v2/authenticatedSites/__tests__/Navigation.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/Navigation.spec.js rename to src/routes/v2/authenticatedSites/__tests__/Navigation.spec.js diff --git a/newroutes/authenticatedSites/__tests__/ResourceCategories.spec.js b/src/routes/v2/authenticatedSites/__tests__/ResourceCategories.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/ResourceCategories.spec.js rename to src/routes/v2/authenticatedSites/__tests__/ResourceCategories.spec.js diff --git a/newroutes/authenticatedSites/__tests__/ResourcePages.spec.js b/src/routes/v2/authenticatedSites/__tests__/ResourcePages.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/ResourcePages.spec.js rename to src/routes/v2/authenticatedSites/__tests__/ResourcePages.spec.js diff --git a/newroutes/authenticatedSites/__tests__/ResourceRoom.spec.js b/src/routes/v2/authenticatedSites/__tests__/ResourceRoom.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/ResourceRoom.spec.js rename to src/routes/v2/authenticatedSites/__tests__/ResourceRoom.spec.js diff --git a/newroutes/authenticatedSites/__tests__/Settings.spec.js b/src/routes/v2/authenticatedSites/__tests__/Settings.spec.js similarity index 96% rename from newroutes/authenticatedSites/__tests__/Settings.spec.js rename to src/routes/v2/authenticatedSites/__tests__/Settings.spec.js index 49cf494ab..214db461f 100644 --- a/newroutes/authenticatedSites/__tests__/Settings.spec.js +++ b/src/routes/v2/authenticatedSites/__tests__/Settings.spec.js @@ -3,7 +3,7 @@ const request = require("supertest") const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler") -const { generateRouter } = require("@fixtures/app.js") +const { generateRouter } = require("@fixtures/app") const { configContent, configSha, configResponse } = require("@fixtures/config") const { footerContent, footerSha, footerResponse } = require("@fixtures/footer") const { homepageContent, homepageSha } = require("@fixtures/homepage") @@ -14,7 +14,7 @@ const { } = require("@fixtures/navigation") const { SettingsService } = require("@services/configServices/SettingsService") -const { SettingsRouter } = require("../settings.js") +const { SettingsRouter } = require("../settings") describe("Settings Router", () => { const mockSettingsService = { diff --git a/newroutes/authenticatedSites/__tests__/UnlinkedPages.spec.js b/src/routes/v2/authenticatedSites/__tests__/UnlinkedPages.spec.js similarity index 100% rename from newroutes/authenticatedSites/__tests__/UnlinkedPages.spec.js rename to src/routes/v2/authenticatedSites/__tests__/UnlinkedPages.spec.js diff --git a/newroutes/authenticatedSites/collectionPages.js b/src/routes/v2/authenticatedSites/collectionPages.js similarity index 100% rename from newroutes/authenticatedSites/collectionPages.js rename to src/routes/v2/authenticatedSites/collectionPages.js diff --git a/newroutes/authenticatedSites/collections.js b/src/routes/v2/authenticatedSites/collections.js similarity index 100% rename from newroutes/authenticatedSites/collections.js rename to src/routes/v2/authenticatedSites/collections.js diff --git a/newroutes/authenticatedSites/contactUs.js b/src/routes/v2/authenticatedSites/contactUs.js similarity index 100% rename from newroutes/authenticatedSites/contactUs.js rename to src/routes/v2/authenticatedSites/contactUs.js diff --git a/newroutes/authenticatedSites/homepage.js b/src/routes/v2/authenticatedSites/homepage.js similarity index 100% rename from newroutes/authenticatedSites/homepage.js rename to src/routes/v2/authenticatedSites/homepage.js diff --git a/newroutes/authenticatedSites/index.js b/src/routes/v2/authenticatedSites/index.js similarity index 88% rename from newroutes/authenticatedSites/index.js rename to src/routes/v2/authenticatedSites/index.js index 935eba6a4..82d578056 100644 --- a/newroutes/authenticatedSites/index.js +++ b/src/routes/v2/authenticatedSites/index.js @@ -2,40 +2,31 @@ const express = require("express") const { CollectionPagesRouter, -} = require("@root/newroutes/authenticatedSites/collectionPages") +} = require("@routes/v2/authenticatedSites/collectionPages") const { CollectionsRouter, -} = require("@root/newroutes/authenticatedSites/collections") -const { - ContactUsRouter, -} = require("@root/newroutes/authenticatedSites/contactUs") -const { - HomepageRouter, -} = require("@root/newroutes/authenticatedSites/homepage") +} = require("@routes/v2/authenticatedSites/collections") +const { ContactUsRouter } = require("@routes/v2/authenticatedSites/contactUs") +const { HomepageRouter } = require("@routes/v2/authenticatedSites/homepage") const { MediaCategoriesRouter, -} = require("@root/newroutes/authenticatedSites/mediaCategories") -const { - MediaFilesRouter, -} = require("@root/newroutes/authenticatedSites/mediaFiles") -const { - NavigationRouter, -} = require("@root/newroutes/authenticatedSites/navigation") +} = require("@routes/v2/authenticatedSites/mediaCategories") +const { MediaFilesRouter } = require("@routes/v2/authenticatedSites/mediaFiles") +const { NavigationRouter } = require("@routes/v2/authenticatedSites/navigation") const { ResourceCategoriesRouter, -} = require("@root/newroutes/authenticatedSites/resourceCategories") +} = require("@routes/v2/authenticatedSites/resourceCategories") const { ResourcePagesRouter, -} = require("@root/newroutes/authenticatedSites/resourcePages") +} = require("@routes/v2/authenticatedSites/resourcePages") const { ResourceRoomRouter, -} = require("@root/newroutes/authenticatedSites/resourceRoom") -const { - SettingsRouter, -} = require("@root/newroutes/authenticatedSites/settings") +} = require("@routes/v2/authenticatedSites/resourceRoom") +const { SettingsRouter } = require("@routes/v2/authenticatedSites/settings") const { UnlinkedPagesRouter, -} = require("@root/newroutes/authenticatedSites/unlinkedPages") +} = require("@routes/v2/authenticatedSites/unlinkedPages") + const { SettingsService } = require("@services/configServices/SettingsService") const { BaseDirectoryService, diff --git a/newroutes/authenticatedSites/mediaCategories.js b/src/routes/v2/authenticatedSites/mediaCategories.js similarity index 100% rename from newroutes/authenticatedSites/mediaCategories.js rename to src/routes/v2/authenticatedSites/mediaCategories.js diff --git a/newroutes/authenticatedSites/mediaFiles.js b/src/routes/v2/authenticatedSites/mediaFiles.js similarity index 100% rename from newroutes/authenticatedSites/mediaFiles.js rename to src/routes/v2/authenticatedSites/mediaFiles.js diff --git a/newroutes/authenticatedSites/navigation.js b/src/routes/v2/authenticatedSites/navigation.js similarity index 100% rename from newroutes/authenticatedSites/navigation.js rename to src/routes/v2/authenticatedSites/navigation.js diff --git a/newroutes/authenticatedSites/resourceCategories.js b/src/routes/v2/authenticatedSites/resourceCategories.js similarity index 100% rename from newroutes/authenticatedSites/resourceCategories.js rename to src/routes/v2/authenticatedSites/resourceCategories.js diff --git a/newroutes/authenticatedSites/resourcePages.js b/src/routes/v2/authenticatedSites/resourcePages.js similarity index 100% rename from newroutes/authenticatedSites/resourcePages.js rename to src/routes/v2/authenticatedSites/resourcePages.js diff --git a/newroutes/authenticatedSites/resourceRoom.js b/src/routes/v2/authenticatedSites/resourceRoom.js similarity index 100% rename from newroutes/authenticatedSites/resourceRoom.js rename to src/routes/v2/authenticatedSites/resourceRoom.js diff --git a/newroutes/authenticatedSites/settings.js b/src/routes/v2/authenticatedSites/settings.js similarity index 100% rename from newroutes/authenticatedSites/settings.js rename to src/routes/v2/authenticatedSites/settings.js diff --git a/newroutes/authenticatedSites/unlinkedPages.js b/src/routes/v2/authenticatedSites/unlinkedPages.js similarity index 100% rename from newroutes/authenticatedSites/unlinkedPages.js rename to src/routes/v2/authenticatedSites/unlinkedPages.js diff --git a/server.js b/src/server.js similarity index 91% rename from server.js rename to src/server.js index 46fe3422e..a57e95d73 100644 --- a/server.js +++ b/src/server.js @@ -14,6 +14,7 @@ import { Deployment, } from "@database/models" import bootstrap from "@root/bootstrap" +import { getAuthMiddleware } from "@root/middleware" import { isomerRepoAxiosInstance } from "@services/api/AxiosInstance" import { getIdentityAuthService, @@ -24,11 +25,10 @@ import DeploymentsService from "@services/identity/DeploymentsService" import ReposService from "@services/identity/ReposService" import InfraService from "@services/infra/InfraService" -import { getAuthMiddleware } from "./newmiddleware" -import getAuthenticatedSubrouter from "./newroutes/authenticated" -import getAuthenticatedSitesSubrouter from "./newroutes/authenticatedSites" -import getAuthenticatedSubrouterV1 from "./routes/authenticated" -import getAuthenticatedSitesSubrouterV1 from "./routes/authenticatedSites" +import getAuthenticatedSubrouterV1 from "./routes/v1/authenticated" +import getAuthenticatedSitesSubrouterV1 from "./routes/v1/authenticatedSites" +import getAuthenticatedSubrouter from "./routes/v2/authenticated" +import getAuthenticatedSitesSubrouter from "./routes/v2/authenticatedSites" const path = require("path") @@ -58,15 +58,15 @@ const { FRONTEND_URL } = process.env const { apiLogger } = require("@middleware/apiLogger") const { errorHandler } = require("@middleware/errorHandler") +const { FormsgRouter } = require("@routes/formsgSiteCreation") +const { AuthRouter } = require("@routes/v2/auth") + const { GitHubService } = require("@services/db/GitHubService") const { ConfigYmlService, } = require("@services/fileServices/YmlFileServices/ConfigYmlService") const { AuthService } = require("@services/utilServices/AuthService") -const { AuthRouter } = require("./newroutes/auth") -const { FormsgRouter } = require("./newroutes/formsgSiteCreation") - const authService = new AuthService({ usersService }) const reposService = new ReposService({ repository: Repo }) const deploymentsService = new DeploymentsService({ repository: Deployment }) diff --git a/services/api/AxiosInstance.ts b/src/services/api/AxiosInstance.ts similarity index 100% rename from services/api/AxiosInstance.ts rename to src/services/api/AxiosInstance.ts diff --git a/services/configServices/NetlifyTomlService.js b/src/services/configServices/NetlifyTomlService.js similarity index 100% rename from services/configServices/NetlifyTomlService.js rename to src/services/configServices/NetlifyTomlService.js diff --git a/services/configServices/SettingsService.js b/src/services/configServices/SettingsService.js similarity index 100% rename from services/configServices/SettingsService.js rename to src/services/configServices/SettingsService.js diff --git a/services/configServices/__tests__/NetlifyTomlService.spec.js b/src/services/configServices/__tests__/NetlifyTomlService.spec.js similarity index 100% rename from services/configServices/__tests__/NetlifyTomlService.spec.js rename to src/services/configServices/__tests__/NetlifyTomlService.spec.js diff --git a/services/configServices/__tests__/SettingsService.spec.js b/src/services/configServices/__tests__/SettingsService.spec.js similarity index 100% rename from services/configServices/__tests__/SettingsService.spec.js rename to src/services/configServices/__tests__/SettingsService.spec.js diff --git a/services/db/GitHubService.js b/src/services/db/GitHubService.js similarity index 100% rename from services/db/GitHubService.js rename to src/services/db/GitHubService.js diff --git a/services/db/__tests__/GitHubService.spec.js b/src/services/db/__tests__/GitHubService.spec.js similarity index 100% rename from services/db/__tests__/GitHubService.spec.js rename to src/services/db/__tests__/GitHubService.spec.js diff --git a/services/directoryServices/BaseDirectoryService.js b/src/services/directoryServices/BaseDirectoryService.js similarity index 100% rename from services/directoryServices/BaseDirectoryService.js rename to src/services/directoryServices/BaseDirectoryService.js diff --git a/services/directoryServices/CollectionDirectoryService.js b/src/services/directoryServices/CollectionDirectoryService.js similarity index 100% rename from services/directoryServices/CollectionDirectoryService.js rename to src/services/directoryServices/CollectionDirectoryService.js diff --git a/services/directoryServices/MediaDirectoryService.js b/src/services/directoryServices/MediaDirectoryService.js similarity index 100% rename from services/directoryServices/MediaDirectoryService.js rename to src/services/directoryServices/MediaDirectoryService.js diff --git a/services/directoryServices/ResourceDirectoryService.js b/src/services/directoryServices/ResourceDirectoryService.js similarity index 100% rename from services/directoryServices/ResourceDirectoryService.js rename to src/services/directoryServices/ResourceDirectoryService.js diff --git a/services/directoryServices/ResourceRoomDirectoryService.js b/src/services/directoryServices/ResourceRoomDirectoryService.js similarity index 100% rename from services/directoryServices/ResourceRoomDirectoryService.js rename to src/services/directoryServices/ResourceRoomDirectoryService.js diff --git a/services/directoryServices/SubcollectionDirectoryService.js b/src/services/directoryServices/SubcollectionDirectoryService.js similarity index 100% rename from services/directoryServices/SubcollectionDirectoryService.js rename to src/services/directoryServices/SubcollectionDirectoryService.js diff --git a/services/directoryServices/UnlinkedPagesDirectoryService.js b/src/services/directoryServices/UnlinkedPagesDirectoryService.js similarity index 100% rename from services/directoryServices/UnlinkedPagesDirectoryService.js rename to src/services/directoryServices/UnlinkedPagesDirectoryService.js diff --git a/services/directoryServices/__tests__/BaseDirectoryService.spec.js b/src/services/directoryServices/__tests__/BaseDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/BaseDirectoryService.spec.js rename to src/services/directoryServices/__tests__/BaseDirectoryService.spec.js diff --git a/services/directoryServices/__tests__/CollectionDirectoryService.spec.js b/src/services/directoryServices/__tests__/CollectionDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/CollectionDirectoryService.spec.js rename to src/services/directoryServices/__tests__/CollectionDirectoryService.spec.js diff --git a/services/directoryServices/__tests__/MediaDirectoryService.spec.js b/src/services/directoryServices/__tests__/MediaDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/MediaDirectoryService.spec.js rename to src/services/directoryServices/__tests__/MediaDirectoryService.spec.js diff --git a/services/directoryServices/__tests__/ResourceDirectoryService.spec.js b/src/services/directoryServices/__tests__/ResourceDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/ResourceDirectoryService.spec.js rename to src/services/directoryServices/__tests__/ResourceDirectoryService.spec.js diff --git a/services/directoryServices/__tests__/ResourceRoomDirectoryService.spec.js b/src/services/directoryServices/__tests__/ResourceRoomDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/ResourceRoomDirectoryService.spec.js rename to src/services/directoryServices/__tests__/ResourceRoomDirectoryService.spec.js diff --git a/services/directoryServices/__tests__/SubcollectionDirectoryService.spec.js b/src/services/directoryServices/__tests__/SubcollectionDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/SubcollectionDirectoryService.spec.js rename to src/services/directoryServices/__tests__/SubcollectionDirectoryService.spec.js diff --git a/services/directoryServices/__tests__/UnlinkedPagesDirectoryService.spec.js b/src/services/directoryServices/__tests__/UnlinkedPagesDirectoryService.spec.js similarity index 100% rename from services/directoryServices/__tests__/UnlinkedPagesDirectoryService.spec.js rename to src/services/directoryServices/__tests__/UnlinkedPagesDirectoryService.spec.js diff --git a/services/fileServices/MdPageServices/CollectionPageService.js b/src/services/fileServices/MdPageServices/CollectionPageService.js similarity index 100% rename from services/fileServices/MdPageServices/CollectionPageService.js rename to src/services/fileServices/MdPageServices/CollectionPageService.js diff --git a/services/fileServices/MdPageServices/ContactUsPageService.js b/src/services/fileServices/MdPageServices/ContactUsPageService.js similarity index 100% rename from services/fileServices/MdPageServices/ContactUsPageService.js rename to src/services/fileServices/MdPageServices/ContactUsPageService.js diff --git a/services/fileServices/MdPageServices/HomepagePageService.js b/src/services/fileServices/MdPageServices/HomepagePageService.js similarity index 100% rename from services/fileServices/MdPageServices/HomepagePageService.js rename to src/services/fileServices/MdPageServices/HomepagePageService.js diff --git a/services/fileServices/MdPageServices/MediaFileService.js b/src/services/fileServices/MdPageServices/MediaFileService.js similarity index 100% rename from services/fileServices/MdPageServices/MediaFileService.js rename to src/services/fileServices/MdPageServices/MediaFileService.js diff --git a/services/fileServices/MdPageServices/ResourcePageService.js b/src/services/fileServices/MdPageServices/ResourcePageService.js similarity index 100% rename from services/fileServices/MdPageServices/ResourcePageService.js rename to src/services/fileServices/MdPageServices/ResourcePageService.js diff --git a/services/fileServices/MdPageServices/SubcollectionPageService.js b/src/services/fileServices/MdPageServices/SubcollectionPageService.js similarity index 99% rename from services/fileServices/MdPageServices/SubcollectionPageService.js rename to src/services/fileServices/MdPageServices/SubcollectionPageService.js index e572adcb5..539dbeff2 100644 --- a/services/fileServices/MdPageServices/SubcollectionPageService.js +++ b/src/services/fileServices/MdPageServices/SubcollectionPageService.js @@ -1,13 +1,12 @@ const { BadRequestError } = require("@errors/BadRequestError") -const { deslugifyCollectionName } = require("@utils/utils") - -const { titleSpecialCharCheck } = require("@validators/validators") - const { retrieveDataFromMarkdown, convertDataToMarkdown, -} = require("../../../utils/markdown-utils") +} = require("@utils/markdown-utils") +const { deslugifyCollectionName } = require("@utils/utils") + +const { titleSpecialCharCheck } = require("@validators/validators") class SubcollectionPageService { constructor({ gitHubService, collectionYmlService }) { diff --git a/services/fileServices/MdPageServices/UnlinkedPageService.js b/src/services/fileServices/MdPageServices/UnlinkedPageService.js similarity index 100% rename from services/fileServices/MdPageServices/UnlinkedPageService.js rename to src/services/fileServices/MdPageServices/UnlinkedPageService.js diff --git a/services/fileServices/MdPageServices/__tests__/CollectionPageService.spec.js b/src/services/fileServices/MdPageServices/__tests__/CollectionPageService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/CollectionPageService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/CollectionPageService.spec.js diff --git a/services/fileServices/MdPageServices/__tests__/ContactUsPageService.spec.js b/src/services/fileServices/MdPageServices/__tests__/ContactUsPageService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/ContactUsPageService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/ContactUsPageService.spec.js diff --git a/services/fileServices/MdPageServices/__tests__/HomepagePageService.spec.js b/src/services/fileServices/MdPageServices/__tests__/HomepagePageService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/HomepagePageService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/HomepagePageService.spec.js diff --git a/services/fileServices/MdPageServices/__tests__/MediaFileService.spec.js b/src/services/fileServices/MdPageServices/__tests__/MediaFileService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/MediaFileService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/MediaFileService.spec.js diff --git a/services/fileServices/MdPageServices/__tests__/ResourcePageService.spec.js b/src/services/fileServices/MdPageServices/__tests__/ResourcePageService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/ResourcePageService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/ResourcePageService.spec.js diff --git a/services/fileServices/MdPageServices/__tests__/SubcollectionPageService.spec.js b/src/services/fileServices/MdPageServices/__tests__/SubcollectionPageService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/SubcollectionPageService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/SubcollectionPageService.spec.js diff --git a/services/fileServices/MdPageServices/__tests__/UnlinkedPageService.spec.js b/src/services/fileServices/MdPageServices/__tests__/UnlinkedPageService.spec.js similarity index 100% rename from services/fileServices/MdPageServices/__tests__/UnlinkedPageService.spec.js rename to src/services/fileServices/MdPageServices/__tests__/UnlinkedPageService.spec.js diff --git a/services/fileServices/YmlFileServices/CollectionYmlService.js b/src/services/fileServices/YmlFileServices/CollectionYmlService.js similarity index 100% rename from services/fileServices/YmlFileServices/CollectionYmlService.js rename to src/services/fileServices/YmlFileServices/CollectionYmlService.js diff --git a/services/fileServices/YmlFileServices/ConfigYmlService.js b/src/services/fileServices/YmlFileServices/ConfigYmlService.js similarity index 100% rename from services/fileServices/YmlFileServices/ConfigYmlService.js rename to src/services/fileServices/YmlFileServices/ConfigYmlService.js diff --git a/services/fileServices/YmlFileServices/FooterYmlService.js b/src/services/fileServices/YmlFileServices/FooterYmlService.js similarity index 100% rename from services/fileServices/YmlFileServices/FooterYmlService.js rename to src/services/fileServices/YmlFileServices/FooterYmlService.js diff --git a/services/fileServices/YmlFileServices/NavYmlService.js b/src/services/fileServices/YmlFileServices/NavYmlService.js similarity index 100% rename from services/fileServices/YmlFileServices/NavYmlService.js rename to src/services/fileServices/YmlFileServices/NavYmlService.js diff --git a/services/fileServices/YmlFileServices/__tests__/CollectionYmlService.spec.js b/src/services/fileServices/YmlFileServices/__tests__/CollectionYmlService.spec.js similarity index 100% rename from services/fileServices/YmlFileServices/__tests__/CollectionYmlService.spec.js rename to src/services/fileServices/YmlFileServices/__tests__/CollectionYmlService.spec.js diff --git a/services/fileServices/YmlFileServices/__tests__/ConfigYmlService.spec.js b/src/services/fileServices/YmlFileServices/__tests__/ConfigYmlService.spec.js similarity index 100% rename from services/fileServices/YmlFileServices/__tests__/ConfigYmlService.spec.js rename to src/services/fileServices/YmlFileServices/__tests__/ConfigYmlService.spec.js diff --git a/services/fileServices/YmlFileServices/__tests__/FooterYmlService.spec.js b/src/services/fileServices/YmlFileServices/__tests__/FooterYmlService.spec.js similarity index 100% rename from services/fileServices/YmlFileServices/__tests__/FooterYmlService.spec.js rename to src/services/fileServices/YmlFileServices/__tests__/FooterYmlService.spec.js diff --git a/services/fileServices/YmlFileServices/__tests__/NavYmlService.spec.js b/src/services/fileServices/YmlFileServices/__tests__/NavYmlService.spec.js similarity index 100% rename from services/fileServices/YmlFileServices/__tests__/NavYmlService.spec.js rename to src/services/fileServices/YmlFileServices/__tests__/NavYmlService.spec.js diff --git a/services/identity/AuthService.ts b/src/services/identity/AuthService.ts similarity index 100% rename from services/identity/AuthService.ts rename to src/services/identity/AuthService.ts diff --git a/services/identity/DeploymentClient.ts b/src/services/identity/DeploymentClient.ts similarity index 100% rename from services/identity/DeploymentClient.ts rename to src/services/identity/DeploymentClient.ts diff --git a/services/identity/DeploymentsService.ts b/src/services/identity/DeploymentsService.ts similarity index 100% rename from services/identity/DeploymentsService.ts rename to src/services/identity/DeploymentsService.ts diff --git a/services/identity/ReposService.ts b/src/services/identity/ReposService.ts similarity index 97% rename from services/identity/ReposService.ts rename to src/services/identity/ReposService.ts index 7a47e09e5..788c5d90b 100644 --- a/services/identity/ReposService.ts +++ b/src/services/identity/ReposService.ts @@ -108,7 +108,6 @@ export default class ReposService { dir, remote, remoteRef: "staging", - corsProxy: "https://cors.isomorphic-git.org", onAuth: () => ({ username: "user", password: SYSTEM_GITHUB_TOKEN }), }) @@ -119,7 +118,6 @@ export default class ReposService { dir, remote, remoteRef: "master", - corsProxy: "https://cors.isomorphic-git.org", onAuth: () => ({ username: "user", password: SYSTEM_GITHUB_TOKEN }), }) } @@ -247,7 +245,6 @@ export default class ReposService { http, dir, remote, - corsProxy: "https://cors.isomorphic-git.org", onAuth: () => ({ username: "user", password: SYSTEM_GITHUB_TOKEN }), } await git.push({ diff --git a/services/identity/SitesService.ts b/src/services/identity/SitesService.ts similarity index 100% rename from services/identity/SitesService.ts rename to src/services/identity/SitesService.ts diff --git a/services/identity/SmsClient.ts b/src/services/identity/SmsClient.ts similarity index 100% rename from services/identity/SmsClient.ts rename to src/services/identity/SmsClient.ts diff --git a/services/identity/TokenStore.ts b/src/services/identity/TokenStore.ts similarity index 100% rename from services/identity/TokenStore.ts rename to src/services/identity/TokenStore.ts diff --git a/services/identity/TotpGenerator.ts b/src/services/identity/TotpGenerator.ts similarity index 100% rename from services/identity/TotpGenerator.ts rename to src/services/identity/TotpGenerator.ts diff --git a/services/identity/UsersService.ts b/src/services/identity/UsersService.ts similarity index 95% rename from services/identity/UsersService.ts rename to src/services/identity/UsersService.ts index e455edacb..a49d7c7fd 100644 --- a/services/identity/UsersService.ts +++ b/src/services/identity/UsersService.ts @@ -3,10 +3,9 @@ import { Sequelize } from "sequelize-typescript" import { RequireAtLeastOne } from "type-fest" import { User, Whitelist } from "@database/models" - -import MailClient from "./MailClient" -import SmsClient from "./SmsClient" -import TotpGenerator from "./TotpGenerator" +import SmsClient from "@services/identity/SmsClient" +import TotpGenerator from "@services/identity/TotpGenerator" +import MailClient from "@services/utilServices/MailClient" interface UsersServiceProps { otp: TotpGenerator diff --git a/services/identity/__tests__/AuthService.spec.ts b/src/services/identity/__tests__/AuthService.spec.ts similarity index 100% rename from services/identity/__tests__/AuthService.spec.ts rename to src/services/identity/__tests__/AuthService.spec.ts diff --git a/services/identity/__tests__/SitesService.spec.ts b/src/services/identity/__tests__/SitesService.spec.ts similarity index 100% rename from services/identity/__tests__/SitesService.spec.ts rename to src/services/identity/__tests__/SitesService.spec.ts diff --git a/services/identity/__tests__/TokenStore.spec.ts b/src/services/identity/__tests__/TokenStore.spec.ts similarity index 100% rename from services/identity/__tests__/TokenStore.spec.ts rename to src/services/identity/__tests__/TokenStore.spec.ts diff --git a/services/identity/__tests__/UsersService.spec.ts b/src/services/identity/__tests__/UsersService.spec.ts similarity index 96% rename from services/identity/__tests__/UsersService.spec.ts rename to src/services/identity/__tests__/UsersService.spec.ts index 1ac5a5759..04a7bc3ec 100644 --- a/services/identity/__tests__/UsersService.spec.ts +++ b/src/services/identity/__tests__/UsersService.spec.ts @@ -2,10 +2,10 @@ import { Sequelize } from "sequelize-typescript" import { ModelStatic } from "sequelize/types" import { User, Whitelist } from "@root/database/models" +import SmsClient from "@services/identity/SmsClient" +import TotpGenerator from "@services/identity/TotpGenerator" +import MailClient from "@services/utilServices/MailClient" -import MailClient from "../MailClient" -import SmsClient from "../SmsClient" -import TotpGenerator from "../TotpGenerator" import _UsersService from "../UsersService" const MockOtp = { diff --git a/services/identity/index.ts b/src/services/identity/index.ts similarity index 91% rename from services/identity/index.ts rename to src/services/identity/index.ts index 162e862c5..3d08d6381 100644 --- a/services/identity/index.ts +++ b/src/services/identity/index.ts @@ -4,13 +4,13 @@ import logger from "@logger/logger" import { User, Site, Whitelist } from "@database/models" import { GitHubService } from "@services/db/GitHubService" +import SmsClient from "@services/identity/SmsClient" +import TotpGenerator from "@services/identity/TotpGenerator" +import { mailer } from "@services/utilServices/MailClient" import AuthService from "./AuthService" -import { mailer } from "./MailClient" import SitesService from "./SitesService" -import SmsClient from "./SmsClient" import TokenStore from "./TokenStore" -import TotpGenerator from "./TotpGenerator" import UsersService from "./UsersService" const { diff --git a/services/infra/InfraService.ts b/src/services/infra/InfraService.ts similarity index 100% rename from services/infra/InfraService.ts rename to src/services/infra/InfraService.ts diff --git a/services/middlewareServices/AuthMiddlewareService.js b/src/services/middlewareServices/AuthMiddlewareService.js similarity index 100% rename from services/middlewareServices/AuthMiddlewareService.js rename to src/services/middlewareServices/AuthMiddlewareService.js diff --git a/services/middlewareServices/FormsProcessingService.ts b/src/services/middlewareServices/FormsProcessingService.ts similarity index 100% rename from services/middlewareServices/FormsProcessingService.ts rename to src/services/middlewareServices/FormsProcessingService.ts diff --git a/services/middlewareServices/__tests__/FormsProcessingService.spec.ts b/src/services/middlewareServices/__tests__/FormsProcessingService.spec.ts similarity index 100% rename from services/middlewareServices/__tests__/FormsProcessingService.spec.ts rename to src/services/middlewareServices/__tests__/FormsProcessingService.spec.ts diff --git a/services/moverServices/MoverService.js b/src/services/moverServices/MoverService.js similarity index 100% rename from services/moverServices/MoverService.js rename to src/services/moverServices/MoverService.js diff --git a/services/moverServices/__tests__/MoverService.spec.js b/src/services/moverServices/__tests__/MoverService.spec.js similarity index 100% rename from services/moverServices/__tests__/MoverService.spec.js rename to src/services/moverServices/__tests__/MoverService.spec.js diff --git a/services/utilServices/AuthService.js b/src/services/utilServices/AuthService.js similarity index 100% rename from services/utilServices/AuthService.js rename to src/services/utilServices/AuthService.js diff --git a/services/identity/MailClient.ts b/src/services/utilServices/MailClient.ts similarity index 100% rename from services/identity/MailClient.ts rename to src/services/utilServices/MailClient.ts diff --git a/services/utilServices/SitesService.js b/src/services/utilServices/SitesService.js similarity index 100% rename from services/utilServices/SitesService.js rename to src/services/utilServices/SitesService.js diff --git a/services/utilServices/__tests__/AuthService.spec.js b/src/services/utilServices/__tests__/AuthService.spec.js similarity index 100% rename from services/utilServices/__tests__/AuthService.spec.js rename to src/services/utilServices/__tests__/AuthService.spec.js diff --git a/services/identity/__tests__/MailClient.spec.ts b/src/services/utilServices/__tests__/MailClient.spec.ts similarity index 96% rename from services/identity/__tests__/MailClient.spec.ts rename to src/services/utilServices/__tests__/MailClient.spec.ts index f5f28f23f..658853730 100644 --- a/services/identity/__tests__/MailClient.spec.ts +++ b/src/services/utilServices/__tests__/MailClient.spec.ts @@ -6,8 +6,7 @@ import { mockBody, mockBearerTokenHeaders, } from "@fixtures/identity" - -import _MailClient from "../MailClient" +import _MailClient from "@services/utilServices/MailClient" const mockEndpoint = "https://api.postman.gov.sg/v1/transactional/email/send" diff --git a/services/utilServices/__tests__/SitesService.spec.js b/src/services/utilServices/__tests__/SitesService.spec.js similarity index 100% rename from services/utilServices/__tests__/SitesService.spec.js rename to src/services/utilServices/__tests__/SitesService.spec.js diff --git a/services/identity/__tests__/SmsClient.spec.ts b/src/services/utilServices/__tests__/SmsClient.spec.ts similarity index 97% rename from services/identity/__tests__/SmsClient.spec.ts rename to src/services/utilServices/__tests__/SmsClient.spec.ts index 24c55f854..560655ff3 100644 --- a/services/identity/__tests__/SmsClient.spec.ts +++ b/src/services/utilServices/__tests__/SmsClient.spec.ts @@ -1,8 +1,7 @@ import mockAxios from "jest-mock-axios" import { mockBody, mockRecipient } from "@fixtures/identity" - -import _SmsClient from "../SmsClient" +import _SmsClient from "@services/identity/SmsClient" const mockEndpoint = "/transactional/sms/send" diff --git a/services/identity/__tests__/TotpGenerator.spec.ts b/src/services/utilServices/__tests__/TotpGenerator.spec.ts similarity index 94% rename from services/identity/__tests__/TotpGenerator.spec.ts rename to src/services/utilServices/__tests__/TotpGenerator.spec.ts index 188f4ed4e..5fe2d30f6 100644 --- a/services/identity/__tests__/TotpGenerator.spec.ts +++ b/src/services/utilServices/__tests__/TotpGenerator.spec.ts @@ -1,6 +1,5 @@ -import { totp as mockTotp } from "@root/__mocks__/otplib" - -import _TotpGenerator from "../TotpGenerator" +import { totp as mockTotp } from "@mocks/otplib" +import _TotpGenerator from "@services/identity/TotpGenerator" const mockSecret = "some secret" const TotpGenerator = new _TotpGenerator({ diff --git a/tests/closeConnection.ts b/src/tests/closeConnection.ts similarity index 100% rename from tests/closeConnection.ts rename to src/tests/closeConnection.ts diff --git a/tests/database.ts b/src/tests/database.ts similarity index 100% rename from tests/database.ts rename to src/tests/database.ts diff --git a/tests/setup.ts b/src/tests/setup.ts similarity index 96% rename from tests/setup.ts rename to src/tests/setup.ts index dfb7820d4..883dbbf66 100644 --- a/tests/setup.ts +++ b/src/tests/setup.ts @@ -17,7 +17,7 @@ const setupDb = async () => { const migrator = new Umzug({ migrations: { - glob: "database/migrations/*.js", + glob: "src/database/migrations/*.js", // NOTE: The below portion is taken directly from the docs // Read more here: https://github.com/sequelize/umzug#modifying-the-parameters-passed-to-your-migration-methods resolve: ({ name, path, context }) => { diff --git a/tests/teardown.ts b/src/tests/teardown.ts similarity index 100% rename from tests/teardown.ts rename to src/tests/teardown.ts diff --git a/types/amplify.ts b/src/types/amplify.ts similarity index 100% rename from types/amplify.ts rename to src/types/amplify.ts diff --git a/types/axios.ts b/src/types/axios.ts similarity index 100% rename from types/axios.ts rename to src/types/axios.ts diff --git a/types/error.ts b/src/types/error.ts similarity index 100% rename from types/error.ts rename to src/types/error.ts diff --git a/types/index.ts b/src/types/index.ts similarity index 100% rename from types/index.ts rename to src/types/index.ts diff --git a/types/request.ts b/src/types/request.ts similarity index 100% rename from types/request.ts rename to src/types/request.ts diff --git a/utils/__tests__/mutex-utils.spec.js b/src/utils/__tests__/mutex-utils.spec.js similarity index 100% rename from utils/__tests__/mutex-utils.spec.js rename to src/utils/__tests__/mutex-utils.spec.js diff --git a/utils/auth-utils.js b/src/utils/auth-utils.js similarity index 100% rename from utils/auth-utils.js rename to src/utils/auth-utils.js diff --git a/utils/axios-utils.js b/src/utils/axios-utils.js similarity index 68% rename from utils/axios-utils.js rename to src/utils/axios-utils.js index d7a465210..b0f7901b2 100644 --- a/utils/axios-utils.js +++ b/src/utils/axios-utils.js @@ -1,7 +1,6 @@ // validateStatus allows axios to handle a 404 HTTP status without rejecting the promise. // This is necessary because GitHub returns a 404 status when the file does not exist. -const validateStatus = (status) => { - return (status >= 200 && status < 300) || status === 404 -} +const validateStatus = (status) => + (status >= 200 && status < 300) || status === 404 module.exports = validateStatus diff --git a/utils/file-upload-utils.js b/src/utils/file-upload-utils.js similarity index 100% rename from utils/file-upload-utils.js rename to src/utils/file-upload-utils.js diff --git a/utils/formsg-utils.ts b/src/utils/formsg-utils.ts similarity index 100% rename from utils/formsg-utils.ts rename to src/utils/formsg-utils.ts diff --git a/utils/jwt-utils.js b/src/utils/jwt-utils.js similarity index 100% rename from utils/jwt-utils.js rename to src/utils/jwt-utils.js diff --git a/utils/markdown-utils.js b/src/utils/markdown-utils.js similarity index 100% rename from utils/markdown-utils.js rename to src/utils/markdown-utils.js diff --git a/utils/mutex-utils.js b/src/utils/mutex-utils.js similarity index 100% rename from utils/mutex-utils.js rename to src/utils/mutex-utils.js diff --git a/utils/route-utils.js b/src/utils/route-utils.js similarity index 100% rename from utils/route-utils.js rename to src/utils/route-utils.js diff --git a/utils/token-retrieval-utils.ts b/src/utils/token-retrieval-utils.ts similarity index 100% rename from utils/token-retrieval-utils.ts rename to src/utils/token-retrieval-utils.ts diff --git a/utils/utils.js b/src/utils/utils.js similarity index 100% rename from utils/utils.js rename to src/utils/utils.js diff --git a/validators/RequestSchema.js b/src/validators/RequestSchema.js similarity index 99% rename from validators/RequestSchema.js rename to src/validators/RequestSchema.js index d0ed9676a..fbc2d0bc8 100644 --- a/validators/RequestSchema.js +++ b/src/validators/RequestSchema.js @@ -1,4 +1,3 @@ -const { required } = require("@root/node_modules/joi/lib/index") const Joi = require("joi") const FileSchema = Joi.object().keys({ diff --git a/validators/validators.js b/src/validators/validators.js similarity index 100% rename from validators/validators.js rename to src/validators/validators.js diff --git a/tsconfig.build.json b/tsconfig.build.json index d04a6d381..5642ace24 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,11 +1,13 @@ -// Main tsconfig for building, prevents tests from being compiled. +// Main tsconfig for building. Prevents config scripts, previous builds, and tests from being compiled. { "extends": "./tsconfig.json", "exclude": [ - "tests/", + "jest.config.js", + "build/", + "src/tests/", "**/*.spec.ts", "**/*.test.ts", "**/__tests__/", - "**/__mocks__/" + "**/__mocks__/", ] } diff --git a/tsconfig.json b/tsconfig.json index 730f83cc9..7b086ea58 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,7 @@ "moduleResolution": "node", "isolatedModules": true, "downlevelIteration": true, - "baseUrl": "./", + "baseUrl": "./src", "resolveJsonModule": true, "sourceMap": true, "experimentalDecorators": true,