🔀 Merge branch 'main' into release/v1.0.5

This commit is contained in:
Eric Doughty-Papassideris
2024-11-25 13:30:27 +01:00
15 changed files with 228 additions and 30 deletions
@@ -15,7 +15,6 @@ import { convert } from "html-to-text";
import path from "path";
import { existsSync } from "fs";
import axios from "axios";
import short, { Translator } from "short-uuid";
import { joinURL } from "../../../../utils/urls";
export default class EmailPusherClass
@@ -43,6 +42,7 @@ export default class EmailPusherClass
});
this.interface = this.configuration.get<string>("email_interface", "");
this.platformUrl = this.configuration.get<string>("platform_url", "");
this.debug = this.configuration.get<boolean>("debug", false);
if (this.interface === "smtp") {
const useTLS = this.configuration.get<string>("smtp_tls", "false") == "true";
const smtpConfig: SMTPClientConfigType = {
@@ -60,7 +60,6 @@ export default class EmailPusherClass
this.apiUrl = this.configuration.get<string>("endpoint", "");
this.apiKey = this.configuration.get<string>("api_key", "");
this.sender = this.configuration.get<string>("sender", "");
this.debug = this.configuration.get<boolean>("debug", false);
}
return this;
@@ -81,20 +80,10 @@ export default class EmailPusherClass
): Promise<EmailBuilderRenderedResult> {
try {
language = ["en", "fr"].find(l => language.toLocaleLowerCase().includes(l)) || "en";
const translator: Translator = short();
const templatePath = path.join(__dirname, "templates", language, `${template}.eta`);
const subjectPath = path.join(__dirname, "templates", language, `${template}.subject.eta`);
const encodedCompanyId = translator.fromUUID(data.notifications[0].item.company_id);
const encodedItemId = translator.fromUUID(data.notifications[0].item.id);
const previewType = data.notifications[0].item.is_directory ? "d" : "preview";
const encodedUrl = joinURL([
this.platformUrl,
"client",
encodedCompanyId,
"v/shared_with_me",
previewType,
encodedItemId,
]);
const urlComponents = data.notifications[0].urlComponents;
const encodedUrl = joinURL([this.platformUrl, ...urlComponents]);
if (!existsSync(templatePath)) {
throw Error(`template not found: ${templatePath}`);
@@ -118,7 +107,7 @@ export default class EmailPusherClass
return { html, text, subject };
} catch (error) {
this.logger.error(`Failure when building email template: ${error}`);
this.logger.error({ error }, `Failure when building email template: ${error}`);
}
}
@@ -150,7 +139,7 @@ export default class EmailPusherClass
};
if (this.debug) {
this.logger.info("EMAIL::SENT ", { emailObject });
this.logger.info({ emailObject }, "EMAIL::SENT");
} else {
if (this.interface === "smtp") {
try {
@@ -9,6 +9,7 @@ export type EmailBuilderDataPayload = {
notifications?: {
type: string;
item: DriveFile;
urlComponents: string[];
}[];
};