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

95 lines
2.9 KiB
TypeScript
Raw Normal View History

chore: Port `ctl` code to Typescript (#37606) This PR converts the Javscript code of the `ctl` module, into Typescript, and in the process already fixing two small bugs that went undetected because... of lack of good type checking. The linting exceptions are still there and will be removed in the next PR. Didn't want to change anymore than necessary or Git will detect these changes as "new files" instead of as "renames". ## 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/11949059369> > Commit: e156dacbc5cb513030052535c3d1f25ce1c7f222 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11949059369&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Thu, 21 Nov 2024 08:45:48 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** - Introduced TypeScript support by updating entry points and adding type definitions for `nodemailer` and `readline-sync`. - Enhanced logging and error handling functionalities across various modules. - **Improvements** - Transitioned from CommonJS to ES module syntax for better compatibility and maintainability. - Improved clarity and structure in command handling and test files. - **Bug Fixes** - Corrected regex patterns and variable declarations in tests to enhance reliability. - **Chores** - Updated dependencies and refined module exports for better organization. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-21 10:07:11 +00:00
import nodemailer from "nodemailer";
import * as Constants from "./constants";
import * as utils from "./utils";
import * as logger from "./logger";
chore: Port `ctl` code to Typescript (#37606) This PR converts the Javscript code of the `ctl` module, into Typescript, and in the process already fixing two small bugs that went undetected because... of lack of good type checking. The linting exceptions are still there and will be removed in the next PR. Didn't want to change anymore than necessary or Git will detect these changes as "new files" instead of as "renames". ## 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/11949059369> > Commit: e156dacbc5cb513030052535c3d1f25ce1c7f222 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11949059369&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Thu, 21 Nov 2024 08:45:48 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** - Introduced TypeScript support by updating entry points and adding type definitions for `nodemailer` and `readline-sync`. - Enhanced logging and error handling functionalities across various modules. - **Improvements** - Transitioned from CommonJS to ES module syntax for better compatibility and maintainability. - Improved clarity and structure in command handling and test files. - **Bug Fixes** - Corrected regex patterns and variable declarations in tests to enhance reliability. - **Chores** - Updated dependencies and refined module exports for better organization. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-21 10:07:11 +00:00
export async function sendBackupErrorToAdmins(err, backupTimestamp) {
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;
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,
},
chore: Port `ctl` code to Typescript (#37606) This PR converts the Javscript code of the `ctl` module, into Typescript, and in the process already fixing two small bugs that went undetected because... of lack of good type checking. The linting exceptions are still there and will be removed in the next PR. Didn't want to change anymore than necessary or Git will detect these changes as "new files" instead of as "renames". ## 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/11949059369> > Commit: e156dacbc5cb513030052535c3d1f25ce1c7f222 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11949059369&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Sanity` > Spec: > <hr>Thu, 21 Nov 2024 08:45:48 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** - Introduced TypeScript support by updating entry points and adding type definitions for `nodemailer` and `readline-sync`. - Enhanced logging and error handling functionalities across various modules. - **Improvements** - Transitioned from CommonJS to ES module syntax for better compatibility and maintainability. - Improved clarity and structure in command handling and test files. - **Bug Fixes** - Corrected regex patterns and variable declarations in tests to enhance reliability. - **Chores** - Updated dependencies and refined module exports for better organization. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-11-21 10:07:11 +00:00
} as any);
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);
}
}