Ghost/ghost/api-version-compatibility-service/lib/api-version-compatibility-service.js
Naz a7fccf1bf8 Fixed email sending
refs https://github.com/TryGhost/Toolbox/issues/292

- The standard sendEmail function used in Ghost accepts three non-optional parameters: to, subject, and html. Have extended the usage with these three required fields
2022-04-21 15:57:43 +08:00

35 lines
1.4 KiB
JavaScript

class APIVersionCompatibilityService {
/**
*
* @param {Object} options
* @param {Function} options.sendEmail - email sending function
* @param {String} options.emailTo - email address to receive notifications
* @param {(acceptVersion: String) => Promise<any>} options.fetchHandled - retrives already handled compatibility notifications
* @param {(acceptVersion: String) => Promise<any>} options.saveHandled - persists already handled compatibility notifications
*/
constructor({sendEmail, emailTo, fetchHandled, saveHandled}) {
this.sendEmail = sendEmail;
this.emailTo = emailTo;
this.fetchHandled = fetchHandled;
this.saveHandled = saveHandled;
}
async handleMismatch({acceptVersion, contentVersion, userAgent}) {
if (!await this.fetchHandled(acceptVersion)) {
const emailTemplate = `
${userAgent} integration expected Ghost version: ${acceptVersion}
Current Ghost version: ${contentVersion}
`;
await this.sendEmail({
subject: `Ghost has noticed that your ${userAgent} integration is no longer working as expected`,
to: this.emailTo,
html: emailTemplate
});
await this.saveHandled(acceptVersion);
}
}
}
module.exports = APIVersionCompatibilityService;