Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion api/src/services/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ const updateDestinationStack = async (req: Request) => {
throw new BadRequestError(HTTP_TEXTS.CANNOT_UPDATE_DESTINATION_STACK);
}

if (project.current_step > STEPPER_STEPS.LEGACY_CMS) {
if (project.current_step > STEPPER_STEPS.DESTINATION_STACK) {
await contentMapperService.resetAllContentTypesMapping(projectId);
logger.info(
getLogMessage(
Expand All @@ -501,6 +501,7 @@ const updateDestinationStack = async (req: Request) => {
)
);
}

try {
const [err, res] = await safePromise(
https({
Expand Down
3 changes: 3 additions & 0 deletions development.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_TOKEN_KEY=MIGRATION_V2
PORT=5000
MONGODB_URI=mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false
10 changes: 10 additions & 0 deletions dist/config/dev.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.devConfig = void 0;
exports.devConfig = {
CS_API: {
NA: "https://stag-api.csnonprod.com/v3",
EU: "https://stag-eu-api.csnonprod.com/v3",
AZURE_NA: "https://stag-azure-na-api.csnonprod.com/v3",
},
};
25 changes: 25 additions & 0 deletions dist/config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.config = void 0;
const dotenv_1 = __importDefault(require("dotenv"));
const path_1 = __importDefault(require("path"));
const prod_config_1 = require("./prod.config");
dotenv_1.default.config({
path: path_1.default.resolve(process.cwd(), `${process.env.NODE_ENV}.env`),
});
exports.config = {
APP_TOKEN_EXP: "1d",
PORT: process.env.PORT,
APP_ENV: process.env.NODE_ENV,
APP_TOKEN_KEY: process.env.APP_TOKEN_KEY,
FILE_UPLOAD_KEY: process.env.FILE_UPLOAD_KEY,
MIGRATION_KEY: process.env.MIGRATION_KEY,
MONGODB_URI: process.env.MONGODB_URI,
AWS_REGION: process.env.AWS_REGION,
UPLOAD_BUCKET: process.env.UPLOAD_BUCKET,
UPLOAD_URL_EXPIRES: 60 * 30,
...(process.env.NODE_ENV === "production" ? prod_config_1.prodConfig : prod_config_1.prodConfig),
};
11 changes: 11 additions & 0 deletions dist/config/prod.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prodConfig = void 0;
exports.prodConfig = {
CS_API: {
NA: "https://api.contentstack.io/v3",
EU: "https://eu-api.contentstack.com/v3",
AZURE_NA: "https://azure-na-api.contentstack.com/v3",
AZURE_EU: "https://azure-eu-api.contentstack.com/v3",
},
};
76 changes: 76 additions & 0 deletions dist/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EXCLUDE_CONTENT_MAPPER = exports.PROJECT_UNSELECTED_FIELDS = exports.CONTENT_TYPE_POPULATE_FIELDS = exports.POPULATE_FIELD_MAPPING = exports.POPULATE_CONTENT_MAPPER = exports.VALIDATION_ERRORS = exports.METHODS_TO_INCLUDE_DATA_IN_AXIOS = exports.HTTP_RESPONSE_HEADERS = exports.HTTP_TEXTS = exports.HTTP_CODES = exports.AXIOS_TIMEOUT = exports.MODULES_ACTIONS = exports.MODULES = exports.CS_REGIONS = void 0;
exports.CS_REGIONS = ["NA", "EU", "AZURE_NA", "AZURE_EU"];
exports.MODULES = [
"Project",
"Migration",
"Content Mapping",
"Legacy CMS",
"Destination Stack",
];
exports.MODULES_ACTIONS = ["Create", "Update", "Delete"];
exports.AXIOS_TIMEOUT = 60 * 1000;
exports.HTTP_CODES = {
OK: 200,
FORBIDDEN: 403,
BAD_REQUEST: 400,
NOT_FOUND: 404,
UNAUTHORIZED: 401,
TOO_MANY_REQS: 429,
SOMETHING_WRONG: 501,
MOVED_PERMANENTLY: 301,
SUPPORT_DOC: 294,
SERVER_ERROR: 500,
UNPROCESSABLE_CONTENT: 422,
};
exports.HTTP_TEXTS = {
UNAUTHORIZED: "You're unauthorized to access this resource.",
INTERNAL_ERROR: "Internal server error, please try again later.",
SOMETHING_WENT_WRONG: "Something went wrong while processing your request, please try again.",
NO_CS_USER: "No user found with the credentials",
SUCCESS_LOGIN: "Login Successful.",
TOKEN_ERROR: "Error occurred during token generation.",
LOGIN_ERROR: "Error occurred during login",
ROUTE_ERROR: "Sorry, the requested resource is not available.",
PROJECT_NOT_FOUND: "Sorry, the requested project does not exists.",
NO_PROJECT: "resource not found with the given ID(s).",
MIGRATION_CREATED: "Project's migration created successfully.",
MIGRATION_UPDATED: "Project's migration updated successfully.",
CMS_UPDATED: "Project's migration cms updated successfully",
FILE_FORMAT_UPDATED: "Project's migration file format updated successfully",
DESTINATION_STACK_UPDATED: "Project's migration destination stack updated successfully",
DESTINATION_STACK_NOT_FOUND: "Destination stack does not exist",
DESTINATION_STACK_ERROR: "Error occurred during verifying destination stack",
MIGRATION_DELETED: "Project's migration deleted successfully.",
INVALID_ID: "Provided $ ID is invalid.",
MIGRATION_EXISTS: "Project's migration already exists.",
CONTENT_TYPE_NOT_FOUND: "ContentType does not exist",
INVALID_CONTENT_TYPE: "Provide valid ContentType data",
RESET_CONTENT_MAPPING: "ContentType has been successfully restored to its initial mapping",
UPLOAD_SUCCESS: "File uploaded successfully",
};
exports.HTTP_RESPONSE_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json",
Connection: "close",
};
exports.METHODS_TO_INCLUDE_DATA_IN_AXIOS = [
"PUT",
"POST",
"DELETE",
"PATCH",
];
exports.VALIDATION_ERRORS = {
INVALID_EMAIL: "Given email ID is invalid.",
EMAIL_LIMIT: "Email's max limit reached.",
LENGTH_LIMIT: "$'s max limit reached.",
STRING_REQUIRED: "Provided $ should be a string.",
INVALID_REGION: "Provided region doesn't exists.",
FIELD_REQUIRED: "Field '$' is required.",
};
exports.POPULATE_CONTENT_MAPPER = "content_mapper";
exports.POPULATE_FIELD_MAPPING = "fieldMapping";
exports.CONTENT_TYPE_POPULATE_FIELDS = "otherCmsTitle otherCmsUid isUpdated updateAt contentstackTitle contentstackUid";
exports.PROJECT_UNSELECTED_FIELDS = "-content_mapper -legacy_cms -destination_stack_id -execution_log";
exports.EXCLUDE_CONTENT_MAPPER = "-content_mapper -execution_log";
16 changes: 16 additions & 0 deletions dist/controllers/auth.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.authController = void 0;
const auth_service_1 = require("../services/auth.service");
const login = async (req, res) => {
const resp = await auth_service_1.authService.login(req);
res.status(resp?.status).json(resp?.data);
};
const RequestSms = async (req, res) => {
const resp = await auth_service_1.authService.requestSms(req);
res.status(resp.status).json(resp.data);
};
exports.authController = {
login,
RequestSms,
};
21 changes: 21 additions & 0 deletions dist/controllers/org.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.orgController = void 0;
const org_service_1 = require("../services/org.service");
const getAllStacks = async (req, res) => {
const resp = await org_service_1.orgService.getAllStacks(req);
res.status(resp?.status).json(resp?.data);
};
const createStack = async (req, res) => {
const resp = await org_service_1.orgService.createStack(req);
res.status(resp.status).json(resp.data);
};
const getLocales = async (req, res) => {
const resp = await org_service_1.orgService.getLocales(req);
res.status(resp.status).json(resp.data);
};
exports.orgController = {
getAllStacks,
createStack,
getLocales,
};
42 changes: 42 additions & 0 deletions dist/controllers/projects.contentMapper.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.contentMapperController = void 0;
const contentMapper_service_1 = require("../services/contentMapper.service");
const putTestData = async (req, res) => {
const resp = await contentMapper_service_1.contentMapperService.putTestData(req);
res.status(200).json(resp);
};
const getContentTypes = async (req, res) => {
const resp = await contentMapper_service_1.contentMapperService.getContentTypes(req);
res.status(200).json(resp);
};
const getFieldMapping = async (req, res) => {
const resp = await contentMapper_service_1.contentMapperService.getFieldMapping(req);
res.status(200).json(resp);
};
const getExistingContentTypes = async (req, res) => {
const resp = await contentMapper_service_1.contentMapperService.getExistingContentTypes(req);
res.status(201).json(resp);
};
const putContentTypeFields = async (req, res) => {
const resp = await contentMapper_service_1.contentMapperService.updateContentType(req);
res.status(200).json(resp);
};
const resetContentType = async (req, res) => {
const resp = await contentMapper_service_1.contentMapperService.resetToInitialMapping(req);
res.status(200).json(resp);
};
// TODO Will remove if not required
// const removeMapping = async (req: Request, res: Response): Promise<void> => {
// const resp = await contentMapperService.removeMapping(req);
// res.status(200).json(resp);
// };
exports.contentMapperController = {
getContentTypes,
getFieldMapping,
getExistingContentTypes,
putTestData,
putContentTypeFields,
resetContentType,
// removeMapping,
};
51 changes: 51 additions & 0 deletions dist/controllers/projects.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.projectController = void 0;
const projects_service_1 = require("../services/projects.service");
const getAllProjects = async (req, res) => {
const allProjects = await projects_service_1.projectService.getAllProjects(req);
res.status(200).json(allProjects);
};
const getProject = async (req, res) => {
const project = await projects_service_1.projectService.getProject(req);
res.status(200).json(project);
};
const getProjectAllDetails = async (req, res) => {
const project = await projects_service_1.projectService.getProjectAllDetails(req);
res.status(200).json(project);
};
const createProject = async (req, res) => {
const project = await projects_service_1.projectService.createProject(req);
res.status(201).json(project);
};
const updateProject = async (req, res) => {
const project = await projects_service_1.projectService.updateProject(req);
res.status(200).json(project);
};
const updateLegacyCMS = async (req, res) => {
const resp = await projects_service_1.projectService.updateLegacyCMS(req);
res.status(resp.status).json(resp.data);
};
const updateFileFormat = async (req, res) => {
const resp = await projects_service_1.projectService.updateFileFormat(req);
res.status(resp.status).json(resp.data);
};
const updateDestinationStack = async (req, res) => {
const resp = await projects_service_1.projectService.updateDestinationStack(req);
res.status(resp.status).json(resp.data);
};
const deleteProject = async (req, res) => {
const project = await projects_service_1.projectService.deleteProject(req);
res.status(200).json(project);
};
exports.projectController = {
getAllProjects,
getProject,
getProjectAllDetails,
createProject,
updateProject,
updateLegacyCMS,
updateFileFormat,
updateDestinationStack,
deleteProject,
};
21 changes: 21 additions & 0 deletions dist/controllers/projects.uploads.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadController = void 0;
const projects_uploads_service_1 = require("../services/projects.uploads.service");
const initializeUpload = async (req, res) => {
const resp = await projects_uploads_service_1.uploadsService.initializeUpload(req);
res.status(resp.status).json(resp.data);
};
const getPreSignedUrls = async (req, res) => {
const resp = await projects_uploads_service_1.uploadsService.getPreSignedUrls(req);
res.status(resp.status).json(resp.data);
};
const finalizeUpload = async (req, res) => {
const resp = await projects_uploads_service_1.uploadsService.finalizeUpload(req);
res.status(resp.status).json(resp.data);
};
exports.uploadController = {
initializeUpload,
getPreSignedUrls,
finalizeUpload,
};
12 changes: 12 additions & 0 deletions dist/controllers/user.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.userController = void 0;
const user_service_1 = require("../services/user.service");
const constants_1 = require("../constants");
const getUserProfile = async (req, res) => {
const user = await user_service_1.userService.getUserProfile(req);
res.status(constants_1.HTTP_CODES.OK).json(user);
};
exports.userController = {
getUserProfile,
};
33 changes: 33 additions & 0 deletions dist/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// database.ts
const mongoose_1 = __importDefault(require("mongoose"));
const config_1 = require("./config");
const logger_1 = __importDefault(require("./utils/logger"));
const project_1 = __importDefault(require("./models/project"));
const authentication_1 = __importDefault(require("./models/authentication"));
const auditLog_1 = __importDefault(require("./models/auditLog"));
const contentTypesMapper_1 = __importDefault(require("./models/contentTypesMapper"));
const FieldMapper_1 = __importDefault(require("./models/FieldMapper"));
const connectToDatabase = async () => {
try {
await mongoose_1.default.connect(config_1.config.MONGODB_URI, {
...(config_1.config.APP_ENV === "production" ? { autoIndex: false } : {}),
});
logger_1.default.info("Connected to MongoDB");
// Create the collection's if it doesn't exist
await project_1.default.init();
await authentication_1.default.init();
await auditLog_1.default.init();
await contentTypesMapper_1.default.init();
await FieldMapper_1.default.init();
}
catch (error) {
logger_1.default.error("Error while connecting to MongoDB:", error);
process.exit(1);
}
};
exports.default = connectToDatabase;
27 changes: 27 additions & 0 deletions dist/middlewares/auth.middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.authenticateUser = void 0;
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
const config_1 = require("../config");
const constants_1 = require("../constants");
const authenticateUser = (req, res, next) => {
const status = constants_1.HTTP_CODES.UNAUTHORIZED;
const token = req.get("app_token");
if (!token)
return res
.status(status)
.json({ status, message: "Unauthorized - Token missing" });
jsonwebtoken_1.default.verify(token, config_1.config.APP_TOKEN_KEY, (err, payload) => {
if (err)
return res
.status(status)
.json({ status, message: "Unauthorized - Invalid token" });
// Attach the payload to the request object for later use
req.body.token_payload = payload;
next();
});
};
exports.authenticateUser = authenticateUser;
15 changes: 15 additions & 0 deletions dist/middlewares/auth.migration.middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.authenticateMigrationService = void 0;
const constants_1 = require("../constants");
const config_1 = require("../config");
const authenticateMigrationService = (req, res, next) => {
const status = constants_1.HTTP_CODES.UNAUTHORIZED;
const secret_key = req.get("secret_key");
if (secret_key !== config_1.config.MIGRATION_KEY)
return res
.status(status)
.json({ status, message: "Unauthorized - Please provide a valid key" });
next();
};
exports.authenticateMigrationService = authenticateMigrationService;
Loading