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
+67
@@ -0,0 +1,67 @@
|
||||
import { loadWebConfig } from "@toolctrl/config";
|
||||
import { getAppConfiguration, updateAppConfiguration } from "~/utils/db/appConfiguration.db.server";
|
||||
|
||||
export const MAILJET_PROVIDER_ID = "mailjet" as const;
|
||||
|
||||
type MailjetProviderId = typeof MAILJET_PROVIDER_ID;
|
||||
type MailjetSource = "environment" | "missing";
|
||||
|
||||
export type MailjetProviderStatus = {
|
||||
id: MailjetProviderId;
|
||||
name: "Mailjet";
|
||||
configured: boolean;
|
||||
source: {
|
||||
apiKey: MailjetSource;
|
||||
secretKey: MailjetSource;
|
||||
fromEmail: MailjetSource;
|
||||
};
|
||||
missing: string[];
|
||||
};
|
||||
|
||||
export type UpdateMailjetSettingsResult =
|
||||
| { success: true }
|
||||
| { success: false; error: string };
|
||||
|
||||
export async function getMailjetProviderStatus({ request }: { request: Request }): Promise<MailjetProviderStatus> {
|
||||
await getAppConfiguration({ request });
|
||||
|
||||
const mailjet = loadWebConfig().config.mailjet;
|
||||
|
||||
const source = {
|
||||
apiKey: mailjet.apiKey ? "environment" : "missing",
|
||||
secretKey: mailjet.secretKey ? "environment" : "missing",
|
||||
fromEmail: mailjet.fromEmail ? "environment" : "missing",
|
||||
} satisfies MailjetProviderStatus["source"];
|
||||
|
||||
const missing = [
|
||||
source.apiKey === "missing" ? "MAILJET_API_KEY" : null,
|
||||
source.secretKey === "missing" ? "MAILJET_SECRET_KEY" : null,
|
||||
source.fromEmail === "missing" ? "MAILJET_FROM_EMAIL" : null,
|
||||
].filter((item): item is string => Boolean(item));
|
||||
|
||||
return {
|
||||
id: MAILJET_PROVIDER_ID,
|
||||
name: "Mailjet",
|
||||
configured: missing.length === 0,
|
||||
source,
|
||||
missing,
|
||||
};
|
||||
}
|
||||
|
||||
export async function updateMailjetSettings(form: FormData): Promise<UpdateMailjetSettingsResult> {
|
||||
const provider = form.get("emailProvider")?.toString();
|
||||
if (provider !== MAILJET_PROVIDER_ID) {
|
||||
return { success: false, error: "Only Mailjet is supported for transactional email." };
|
||||
}
|
||||
|
||||
if (form.get("apiKey")?.toString().trim()) {
|
||||
return { success: false, error: "Mailjet API keys are configured through environment variables only." };
|
||||
}
|
||||
|
||||
await updateAppConfiguration({
|
||||
emailProvider: MAILJET_PROVIDER_ID,
|
||||
emailSupportEmail: form.get("emailSupportEmail")?.toString(),
|
||||
});
|
||||
|
||||
return { success: true };
|
||||
}
|
||||
Reference in new issue
Block a user