Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,63 @@
|
||||
import { getAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
import { createScopedLogger } from "~/utils/logger.server";
|
||||
import { sendEmailMailjet } from "./MailjetEmailService";
|
||||
|
||||
const emailLogger = createScopedLogger("email");
|
||||
|
||||
type EmailProvider = "mailjet";
|
||||
|
||||
export async function sendEmail({
|
||||
request,
|
||||
to,
|
||||
subject,
|
||||
body,
|
||||
alias,
|
||||
data,
|
||||
tenantId,
|
||||
priorityOverride,
|
||||
}: {
|
||||
request: Request;
|
||||
to: string;
|
||||
subject: string;
|
||||
body: string;
|
||||
alias?: string;
|
||||
data?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
tenantId?: string | null;
|
||||
priorityOverride?: "critical" | "high" | "normal" | "low";
|
||||
}) {
|
||||
const config = await getEmailConfig({ request, throwError: true });
|
||||
if (!config) {
|
||||
throw new Error("Email provider not configured");
|
||||
}
|
||||
// Intentionally never log `to`, `subject`, `body`, or `data` (PII).
|
||||
// Only log provider class, presence-of-alias, and a generic flag for template data.
|
||||
emailLogger.info(
|
||||
{
|
||||
provider: config.provider,
|
||||
hasAlias: typeof alias === "string" && alias.length > 0,
|
||||
hasTemplateData: Boolean(data),
|
||||
},
|
||||
"Sending email",
|
||||
);
|
||||
return await sendEmailMailjet({ data: { to, subject, body, alias, data, tenantId, priorityOverride } });
|
||||
}
|
||||
|
||||
export async function getEmailProvider({ request }: { request: Request }) {
|
||||
const clientConfig = await getEmailConfig({ request });
|
||||
return clientConfig?.provider;
|
||||
}
|
||||
|
||||
export async function getEmailConfig({ request, throwError = false }: { request: Request; throwError?: boolean }) {
|
||||
const appConfiguration = await getAppConfiguration({ request });
|
||||
let provider = appConfiguration.email.provider;
|
||||
if (provider === "mailjet") {
|
||||
return appConfiguration.email;
|
||||
}
|
||||
emailLogger.error({ provider: provider ?? "<none>" }, "Email provider not configured");
|
||||
if (throwError) {
|
||||
throw new Error("Email provider not configured");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user