PromucFlow_constructor/app/client/packages/rts/src/ctl/mailer.js

97 lines
3.0 KiB
JavaScript
Raw Normal View History

chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
const nodemailer = require("nodemailer");
const Constants = require("./constants");
const utils = require("./utils");
const logger = require("./logger");
const mailEnabled = process.env.APPSMITH_MAIL_ENABLED;
const mailFrom = process.env.APPSMITH_MAIL_FROM;
const mailHost = process.env.APPSMITH_MAIL_HOST;
const mailPort = process.env.APPSMITH_MAIL_PORT;
const mailUser = process.env.APPSMITH_MAIL_USERNAME;
const mailPass = process.env.APPSMITH_MAIL_PASSWORD;
const mailTo = process.env.APPSMITH_ADMIN_EMAILS;
async function sendBackupErrorToAdmins(err, backupTimestamp) {
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
console.log("Sending Error mail to admins.");
try {
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
if (
!mailEnabled ||
!mailFrom ||
!mailHost ||
!mailPort ||
!mailUser ||
!mailPass
) {
throw new Error(
"Failed to send error mail. Email provider is not configured, please refer to https://docs.appsmith.com/setup/instance-configuration/email to configure it.",
);
} else if (!mailTo) {
throw new Error(
"Failed to send error mail. Admin email(s) not configured, please refer to https://docs.appsmith.com/setup/instance-configuration/disable-user-signup#administrator-emails to configure it.",
);
} else if (!mailEnabled) {
throw new Error(
"Mail not sent! APPSMITH_MAIL_ENABLED env val is disabled, please refer to https://docs.appsmith.com/setup/instance-configuration/email to enable it.",
);
} else {
const backupFiles = await utils.listLocalBackupFiles();
const lastBackupfile = backupFiles.pop();
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
const lastBackupTimestamp = lastBackupfile.match(
/appsmith-backup-(.*)\.tar.gz/,
)[1];
const lastBackupPath = Constants.BACKUP_PATH + "/" + lastBackupfile;
const domainName = process.env.APPSMITH_CUSTOM_DOMAIN;
const instanceName = process.env.APPSMITH_INSTANCE_NAME;
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
let text =
"Appsmith backup did not complete successfully.\n\n " +
"Backup timestamp: " +
backupTimestamp +
"\n\n" +
"Last Successful Backup timestamp: " +
lastBackupTimestamp +
"\n" +
"Last Successful Backup location: " +
lastBackupPath +
"\n\n";
if (instanceName) {
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
text = text + "Appsmith instance name: " + instanceName + "\n";
}
if (domainName) {
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
text =
text +
"Link to Appsmith admin settings: " +
"http://" +
domainName +
"/settings/general" +
"\n";
}
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
text = text + "\n" + err.stack;
const transporter = nodemailer.createTransport({
host: mailHost,
port: mailPort,
auth: {
user: mailUser,
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
pass: mailPass,
},
});
await transporter.sendMail({
from: mailFrom,
to: mailTo,
chore: Format appsmithctl code (#37532) Formatting just before merging `appsmithctl` code into RTS. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11890257914> > Commit: 5c838014b7b5b34058c8a92de28a51429a54ceda > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11890257914&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Mon, 18 Nov 2024 10:46:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added constants for backup and restore paths, database dump file names, and email notifications related to backup errors. - Introduced a new function for running restore operations. - **Bug Fixes** - Enhanced error handling and logging for backup and restore processes. - **Documentation** - Improved clarity in console log messages across various utilities. - **Refactor** - Standardized string formatting and code structure for better readability and maintainability across multiple files, including consistent use of double quotes and improved error handling formatting. - **Tests** - Expanded test coverage for backup utilities and improved formatting for better readability in test cases. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-19 05:41:21 +00:00
subject: "[Appsmith] ERROR: Backup Failed",
text: text,
});
}
} catch (err) {
await logger.backup_error(err.stack);
}
}
module.exports = {
sendBackupErrorToAdmins,
chore: Remove `shelljs` from more `appsmithctl` commands (#37383) This PR removes more uses of `shelljs` from the `appsmithctl` project, towards completely removing that dependency. Then we should be able to build `appsmithctl` with `esbuild`, and reduce false-positive CVEs being reported from `appsmithctl`'s `node_modules` folder. ## Automation /test sanity ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/11833714062> > Commit: d63aa150dff9f8117544219e2f2dfc5816e978a8 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11833714062&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Thu, 14 Nov 2024 09:21:47 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Enhanced backup and restore processes with improved error handling and logging. - Introduced a new utility function to check if the Supervisor process is running. - **Bug Fixes** - Improved error messages for password retrieval during backup operations. - Refined cleanup processes to ensure resources are released properly. - **Documentation** - Updated test cases for backup functionalities to cover more scenarios and ensure asynchronous handling. - **Chores** - Removed unnecessary dependencies and streamlined logging methods across various scripts. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-14 13:47:19 +00:00
};