Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat(auth): email on MFA enforcement and enrollment (#1445)
Naveen Kashyapa456ba944247
diff --git a/.claude/rules/authentication-system.md b/.claude/rules/authentication-system.mdindex 4c6b639a25..ec1f9adc55 100644--- a/.claude/rules/authentication-system.md+++ b/.claude/rules/authentication-system.md@@ -109,6 +109,25 @@ Supabase's `auth.mfa_factors` — no app table.MFA is not gated, and the shell re-runs on company switch. Console sessions areexempt (a shared kiosk cannot complete a personal enrollment); MES has noenrollment UI so its gate links to ERP.+- **Email**: `~/services/mfa-email.server.ts` owns both MFA emails+ (`MfaRequiredEmail` / `MfaEnabledEmail` in `@carbon/documents/email`).+ `sendMfaRequiredEmails` fires from the settings action on the **off → on+ transition only** (it re-reads `companySettings.requireMfa` first — the Switch+ re-submits on every flip), and batches active employees through+ `batchTrigger("send-email", …)` 25 at a time. It is additionally skipped when+ `CONTROLLED_ENVIRONMENT` — effective enforcement there is+ `CONTROLLED_ENVIRONMENT || requireMfa` and NOTHING ever writes the column, so+ it sits `false` while MFA is already mandatory; the column alone would read as+ a fresh transition and announce a requirement that predates the deployment.+ The Switch is `disabled` in that mode, but the action has no such guard, so+ this cannot live in the UI. `sendMfaEnabledEmail` fires from+ `api+/mfa.verify` — that route only ever verifies an ENROLLMENT (a login+ challenge goes through `completeMfaChallenge` on `/mfa`), so reaching it means+ a factor was just added. Both take a service-role client, and NEITHER goes+ through `trigger("notify", …)`: security mail must not be silenced by a+ `notificationPreference` opt-out or gated on the `EMAIL_NOTIFICATIONS` plan+ feature. Both swallow their own errors — enrollment and the setting flip must+ not fail because email did.- **Admin visibility**: the `users_with_verified_mfa(company_id)` RPC(SECURITY DEFINER — `auth.mfa_factors` is unreachable from the SECURITY_INVOKER`employees` view) backs the Two-Factor column on employee accounts. It returnsdiff --git a/apps/erp/app/modules/agent/kb/docs/reference/two-factor.md b/apps/erp/app/modules/agent/kb/docs/reference/two-factor.mdindex 132b416ecb..faa11fb883 100644--- a/apps/erp/app/modules/agent/kb/docs/reference/two-factor.md+++ b/apps/erp/app/modules/agent/kb/docs/reference/two-factor.md@@ -14,6 +14,8 @@ Press **"Add Authenticator App"**. Carbon shows a QR code and, beneath it, the sNothing is active until that code checks out. Until then the factor is `unverified` and Carbon ignores it entirely, which is why abandoning the dialog halfway leaves nothing behind.+The moment it does check out, Carbon emails you a receipt — "Two-factor authentication is on". It isn't a notification you can turn off, because its whole purpose is to be the one signal you'd get if somebody else enrolled an authenticator against your account. If one arrives that you didn't cause, remove the factor and tell an admin.+The entry is labelled with the company you were in when you enrolled, over your email — `Carbon (Acme Manufacturing)` above `[email protected]`. That's deliberate. If you use Carbon at more than one organization, two entries both reading "Carbon" would be indistinguishable at the moment you need to tell them apart.The label is written into the QR when you enrol. Renaming the company later doesn't rewrite anyone's existing entry.@@ -36,6 +38,10 @@ Sessions that already existed before you enrolled don't get a free pass. CarbonOpen **Settings → System → Security** and find the **Two-Factor Authentication Enforcement** card. Turning the switch on means anyone opening that company has to have an authenticator set up. There's no grace period; it takes effect on their next page load.+Flipping the switch on also emails every active employee of the company, so nobody's first warning is a locked screen. The message names the company, links straight to **Account → Security**, and tells people who already have an authenticator that nothing changes for them.++It goes out on each off → on transition. Turning enforcement *off* sends nothing, and re-saving a setting that is already on sends nothing either. But if you disable enforcement and later switch it back on, everyone is emailed again — by that point they've been told the requirement was lifted, so they need telling that it's back.+Someone without one sees a full-screen prompt instead of the app, with a **"Set up authenticator app"** button that runs the same QR-and-code flow as the account page. They can complete it right there. The only other thing on that screen is **"Sign out"** — there is no way past it.This is the part worth reading twice. If you belong to two companies and only one requires two-factor, you're prompted to set one up **only while you're in that company**. Switch to the other and the prompt is gone.@@ -92,7 +98,11 @@ The column only renders while the company requires two-factor. Turn the setting### Turning enforcement on didn't prompt anyone-It applies on each person's next page load, not retroactively to sessions sitting idle. Anyone already looking at a stale tab sees it when they next navigate.+It applies on each person's next page load, not retroactively to sessions sitting idle. Anyone already looking at a stale tab sees it when they next navigate. The announcement email is what reaches them in the meantime.++### Nobody got the announcement email++It's sent only when the setting actually changes from off to on. If it was already on — someone else flipped it, or the deployment is a controlled environment where it's locked on — there's no transition to announce. It also goes only to **active** employees, so anyone deactivated isn't included.### An admin can't turn enforcement offdiff --git a/apps/erp/app/modules/agent/kb/manifest.json b/apps/erp/app/modules/agent/kb/manifest.jsonindex 357521a8c4..90885806bb 100644--- a/apps/erp/app/modules/agent/kb/manifest.json+++ b/apps/erp/app/modules/agent/kb/manifest.json@@ -1551,6 +1551,7 @@"Someone is stuck on the setup screen and can't get in","The Two-Factor column isn't in the employee list","Turning enforcement on didn't prompt anyone",+ "Nobody got the announcement email","An admin can't turn enforcement off"]},diff --git a/apps/erp/app/routes/api+/mfa.verify.ts b/apps/erp/app/routes/api+/mfa.verify.tsindex 2ed2cc03ab..dc8672479a 100644--- a/apps/erp/app/routes/api+/mfa.verify.ts+++ b/apps/erp/app/routes/api+/mfa.verify.ts@@ -1,5 +1,6 @@import { assertIsPost, error, RATE_LIMIT, success } from "@carbon/auth";import { makeAuthSession, requirePermissions } from "@carbon/auth/auth.server";+import { getCarbonServiceRole } from "@carbon/auth/client.server";import { verifyTotpChallenge } from "@carbon/auth/mfa.server";import {requireAuthSession,@@ -8,6 +9,7 @@ import {import { Ratelimit, redis } from "@carbon/kv";import type { ActionFunctionArgs } from "react-router";import { data } from "react-router";+import { sendMfaEnabledEmail } from "~/services/mfa-email.server";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);@@ -71,6 +73,15 @@ export async function action({ request }: ActionFunctionArgs) {authSession: newAuthSession});+ // This route only ever verifies an ENROLLMENT — a login challenge goes+ // through completeMfaChallenge on /mfa — so reaching here means a factor was+ // just added to this account. Send the receipt; it never throws.+ await sendMfaEnabledEmail(+ getCarbonServiceRole(),+ authSession.companyId,+ authSession.userId+ );+return data(success("Two-factor authentication enabled"), {headers: { "Set-Cookie": sessionCookie }});diff --git a/apps/erp/app/routes/x+/settings+/security.tsx b/apps/erp/app/routes/x+/settings+/security.tsxindex a4365374fc..7a44a24fb3 100644--- a/apps/erp/app/routes/x+/settings+/security.tsx+++ b/apps/erp/app/routes/x+/settings+/security.tsx@@ -5,6 +5,7 @@ import {success} from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";+import { getCarbonServiceRole } from "@carbon/auth/client.server";import { flash } from "@carbon/auth/session.server";import {Card,@@ -24,6 +25,7 @@ import { data, Link, useFetcher } from "react-router";import { usePermissions } from "~/hooks";import { useSettings } from "~/hooks/useSettings";import { updateRequireMfaSetting } from "~/modules/settings";+import { sendMfaRequiredEmails } from "~/services/mfa-email.server";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";@@ -48,6 +50,15 @@ export async function action({ request }: ActionFunctionArgs) {const formData = await request.formData();const requireMfa = formData.get("enabled") === "true";++ // Read the stored value first: the switch re-submits on every flip, and a+ // toggle that lands on the value it already had must not re-announce.+ const previous = await client+ .from("companySettings")+ .select("requireMfa")+ .eq("id", companyId)+ .single();+const update = await updateRequireMfaSetting(client, companyId, requireMfa);if (update.error)return data(@@ -58,6 +69,24 @@ export async function action({ request }: ActionFunctionArgs) {));+ // Only the off → on transition is news. If the prior read failed we don't+ // know it was a transition, so we stay quiet rather than mailing the company.+ //+ // CONTROLLED_ENVIRONMENT is checked separately because effective enforcement+ // is `CONTROLLED_ENVIRONMENT || requireMfa` (see the ERP/MES shell loaders),+ // and nothing ever writes the column in such a deployment — it stays false+ // while MFA is already mandatory. Without this guard the column would read as+ // a fresh off → on and the company would be told a requirement "now" applies+ // that has applied since the day it was deployed. Enforcement there is a+ // deployment fact, not an event, so there is nothing to announce.+ if (+ !CONTROLLED_ENVIRONMENT &&+ requireMfa &&+ previous.data?.requireMfa === false+ ) {+ await sendMfaRequiredEmails(getCarbonServiceRole(), companyId);+ }+return data({},await flash(diff --git a/apps/erp/app/services/mfa-email.server.ts b/apps/erp/app/services/mfa-email.server.tsnew file mode 100644index 0000000000..5d386b0019--- /dev/null+++ b/apps/erp/app/services/mfa-email.server.ts@@ -0,0 +1,144 @@+import type { Database } from "@carbon/database";+import { MfaEnabledEmail, MfaRequiredEmail } from "@carbon/documents/email";+import { batchTrigger, trigger } from "@carbon/jobs";+import { getLogger } from "@carbon/logger";+import { chunkArray } from "@carbon/utils";+import { render } from "@react-email/components";+import type { SupabaseClient } from "@supabase/supabase-js";+import { getUser } from "~/modules/users/users.server";+import { ERP_URL, path } from "~/utils/path";++const logger = getLogger("erp", "mfa-email");++// Recipients per Inngest send. `batchTrigger` has no size cap of its own, so+// chunking is the caller's job — as it is for every other fan-out in the repo+// (INSERT_CHUNK_SIZE, RECONCILE_BATCH_SIZE, …), each tuned to its own payload.+// The announcement runs inside the request that flipped the setting, so it+// can't be one round trip per employee; 25 keeps a 300-person company to a+// dozen sends while capping each request body (a rendered email is ~20 KB) and+// limiting what a single failed send costs.+const EMAIL_BATCH_SIZE = 25;++// No shared helper exists for "absolute URL from a path.to.* value" — inline+// concatenation is the convention at every call site (~9 of this exact shape).+const SECURITY_URL = `${ERP_URL}${path.to.accountSecurity}`;++/**+ * Announce a newly-turned-on two-factor requirement to every active employee of+ * the company.+ *+ * Deliberately NOT routed through `trigger("notify", ...)`: this is a security+ * announcement, so it must not be silenced by a per-user notification+ * preference or gated on the company's EMAIL_NOTIFICATIONS plan feature.+ *+ * Never throws — turning the setting on must not fail because email did.+ * Callers pass a service-role client: the announcement covers every employee,+ * including ones the acting admin's RLS scope wouldn't return.+ */+export async function sendMfaRequiredEmails(+ serviceRole: SupabaseClient<Database>,+ companyId: string+) {+ try {+ const [company, employees] = await Promise.all([+ serviceRole.from("company").select("name").eq("id", companyId).single(),+ serviceRole+ .from("employees")+ .select("id, email, name")+ .eq("companyId", companyId)+ .eq("active", true)+ ]);++ if (company.error) throw company.error;+ if (employees.error) throw employees.error;++ const setupUrl = SECURITY_URL;+ const companyName = company.data.name;+ const subject = `Two-factor authentication is now required for ${companyName}`;+ const recipients = (employees.data ?? []).filter(+ (employee): employee is typeof employee & { email: string } =>+ !!employee.email+ );++ for (const batch of chunkArray(recipients, EMAIL_BATCH_SIZE)) {+ try {+ // The greeting is per-recipient, so each email is rendered separately.+ const items = await Promise.all(+ batch.map(async (employee) => {+ const email = MfaRequiredEmail({+ recipientName: employee.name ?? undefined,+ companyName,+ setupUrl+ });+ return {+ payload: {+ to: [employee.email],+ subject,+ html: await render(email),+ text: await render(email, { plainText: true }),+ companyId+ }+ };+ })+ );+ await batchTrigger("send-email", items);+ } catch (err) {+ logger.error(+ "Failed to send a batch of two-factor requirement emails",+ {+ companyId,+ employeeIds: batch.map((employee) => employee.id ?? "unknown"),+ error: err+ }+ );+ }+ }+ } catch (err) {+ logger.error("Failed to announce two-factor requirement", {+ companyId,+ error: err+ });+ }+}++/**+ * Confirm to a user that an authenticator app was added to their own account —+ * the receipt that lets them notice an enrollment they didn't perform.+ *+ * Same reasoning as above: account-security mail, so no preference or plan+ * gating, and it never throws (the factor is already verified by the time this+ * runs — failing the request would leave the user with MFA on and an error).+ */+export async function sendMfaEnabledEmail(+ serviceRole: SupabaseClient<Database>,+ companyId: string,+ userId: string+) {+ try {+ // getUser also filters `active` — correct here, since the recipient just+ // cleared requirePermissions to reach the verify route.+ const user = await getUser(serviceRole, userId);++ if (user.error) throw user.error;+ if (!user.data.email) return;++ const email = MfaEnabledEmail({+ recipientName: user.data.fullName ?? undefined,+ securityUrl: SECURITY_URL+ });++ await trigger("send-email", {+ to: [user.data.email],+ subject: "Two-factor authentication is on for your Carbon account",+ html: await render(email),+ text: await render(email, { plainText: true }),+ companyId+ });+ } catch (err) {+ logger.error("Failed to send two-factor enabled email", {+ companyId,+ userId,+ error: err+ });+ }+}diff --git a/docs/content/docs/reference/two-factor.mdx b/docs/content/docs/reference/two-factor.mdxindex 7b0a104e0c..8264063aac 100644--- a/docs/content/docs/reference/two-factor.mdx+++ b/docs/content/docs/reference/two-factor.mdx@@ -15,6 +15,8 @@ Press **"Add Authenticator App"**. Carbon shows a QR code and, beneath it, the sNothing is active until that code checks out. Until then the factor is `unverified` and Carbon ignores it entirely, which is why abandoning the dialog halfway leaves nothing behind.+The moment it does check out, Carbon emails you a receipt — "Two-factor authentication is on". It isn't a notification you can turn off, because its whole purpose is to be the one signal you'd get if somebody else enrolled an authenticator against your account. If one arrives that you didn't cause, remove the factor and tell an admin.+<Callout type="info" title="What you'll see in your authenticator app">The entry is labelled with the company you were in when you enrolled, over your email — `Carbon (Acme Manufacturing)` above `[email protected]`. That's deliberate. If you use Carbon at more than one organization, two entries both reading "Carbon" would be indistinguishable at the moment you need to tell them apart.@@ -41,6 +43,10 @@ Sessions that already existed before you enrolled don't get a free pass. CarbonOpen **Settings → System → Security** and find the **Two-Factor Authentication Enforcement** card. Turning the switch on means anyone opening that company has to have an authenticator set up. There's no grace period; it takes effect on their next page load.+Flipping the switch on also emails every active employee of the company, so nobody's first warning is a locked screen. The message names the company, links straight to **Account → Security**, and tells people who already have an authenticator that nothing changes for them.++It goes out on each off → on transition. Turning enforcement *off* sends nothing, and re-saving a setting that is already on sends nothing either. But if you disable enforcement and later switch it back on, everyone is emailed again — by that point they've been told the requirement was lifted, so they need telling that it's back.+Someone without one sees a full-screen prompt instead of the app, with a **"Set up authenticator app"** button that runs the same QR-and-code flow as the account page. They can complete it right there. The only other thing on that screen is **"Sign out"** — there is no way past it.<Callout type="note" title="The requirement is per company; the authenticator is per person">@@ -105,7 +111,11 @@ The column only renders while the company requires two-factor. Turn the setting### Turning enforcement on didn't prompt anyone-It applies on each person's next page load, not retroactively to sessions sitting idle. Anyone already looking at a stale tab sees it when they next navigate.+It applies on each person's next page load, not retroactively to sessions sitting idle. Anyone already looking at a stale tab sees it when they next navigate. The announcement email is what reaches them in the meantime.++### Nobody got the announcement email++It's sent only when the setting actually changes from off to on. If it was already on — someone else flipped it, or the deployment is a controlled environment where it's locked on — there's no transition to announce. It also goes only to **active** employees, so anyone deactivated isn't included.### An admin can't turn enforcement offdiff --git a/packages/documents/src/email/ImplementationHubEmail.tsx b/packages/documents/src/email/ImplementationHubEmail.tsxindex f5d1659748..87c43ad8f5 100644--- a/packages/documents/src/email/ImplementationHubEmail.tsx+++ b/packages/documents/src/email/ImplementationHubEmail.tsx@@ -9,6 +9,7 @@ import {Text} from "@react-email/components";import { Logo } from "./components/Logo";+import { notificationStyles } from "./components/notificationStyles";import { EmailThemeProvider, getEmailThemeClasses } from "./components/Theme";interface Props {@@ -16,153 +17,6 @@ interface Props {hubUrl: string;}-// Dark-mode-aware styles. Backgrounds are intentionally set via CSS classes-// (not inline styles) so `!important` overrides in dark-mode media queries-// can flip them — inline `style` wins against non-important CSS, but loses to-// `!important`. Most modern clients (Apple Mail, iOS Mail, Gmail web/iOS,-// Outlook web/mobile) honor this; Outlook desktop renders light-mode only,-// matching the rest of the system.-const notificationStyles = `- .nf-body {- background-color: #f5f5f7;- background-image: linear-gradient(180deg, #f5f5f7 0%, #ececef 100%);- }- .nf-card {- background-color: #ffffff;- background-image: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);- border-color: #e5e7eb;- }- .nf-divider {- border-color: #ececef !important;- }- .nf-eyebrow {- color: #6b7280 !important;- }- .nf-callout {- background-color: #fafafa !important;- border-color: #ececef !important;- }- .nf-callout-accent {- background-color: #0e0e0e !important;- }- .nf-cta {- background-color: #0e0e0e !important;- color: #ffffff !important;- border-color: #0e0e0e !important;- }- .nf-fallback {- color: #6b7280 !important;- }-- @media (prefers-color-scheme: dark) {- .nf-body {- background-color: #0C0C0C !important;- background-image: linear-gradient(180deg, #0C0C0C 0%, #161618 100%) !important;- }- .nf-card {- background-color: #161618 !important;- background-image: linear-gradient(180deg, #161618 0%, #0F0F10 100%) !important;- border-color: #1D1D1D !important;- }- .nf-divider {- border-color: #1D1D1D !important;- }- .nf-eyebrow {- color: #a1a1aa !important;- }- .nf-callout {- background-color: #0F0F10 !important;- border-color: #1D1D1D !important;- }- .nf-callout-accent {- background-color: #fefefe !important;- }- .nf-cta {- background-color: #fefefe !important;- color: #0C0C0C !important;- border-color: #fefefe !important;- }- .nf-fallback {- color: #a1a1aa !important;- }- }-- /* Gmail desktop dark mode targeting */- .gmail_dark .nf-body,- .gmail_dark_theme .nf-body,- [data-darkmode="true"] .nf-body {- background-color: #0C0C0C !important;- background-image: linear-gradient(180deg, #0C0C0C 0%, #161618 100%) !important;- }- .gmail_dark .nf-card,- .gmail_dark_theme .nf-card,- [data-darkmode="true"] .nf-card {- background-color: #161618 !important;- background-image: linear-gradient(180deg, #161618 0%, #0F0F10 100%) !important;- border-color: #1D1D1D !important;- }- .gmail_dark .nf-divider,- .gmail_dark_theme .nf-divider,- [data-darkmode="true"] .nf-divider {- border-color: #1D1D1D !important;- }- .gmail_dark .nf-eyebrow,- .gmail_dark_theme .nf-eyebrow,- [data-darkmode="true"] .nf-eyebrow {- color: #a1a1aa !important;- }- .gmail_dark .nf-callout,- .gmail_dark_theme .nf-callout,- [data-darkmode="true"] .nf-callout {- background-color: #0F0F10 !important;- border-color: #1D1D1D !important;- }- .gmail_dark .nf-callout-accent,- .gmail_dark_theme .nf-callout-accent,- [data-darkmode="true"] .nf-callout-accent {- background-color: #fefefe !important;- }- .gmail_dark .nf-cta,- .gmail_dark_theme .nf-cta,- [data-darkmode="true"] .nf-cta {- background-color: #fefefe !important;- color: #0C0C0C !important;- border-color: #fefefe !important;- }- .gmail_dark .nf-fallback,- .gmail_dark_theme .nf-fallback,- [data-darkmode="true"] .nf-fallback {- color: #a1a1aa !important;- }-- /* Outlook web/mobile dark mode targeting */- [data-ogsb] .nf-body {- background-color: #0C0C0C !important;- }- [data-ogsb] .nf-card {- background-color: #161618 !important;- border-color: #1D1D1D !important;- }- [data-ogsb] .nf-callout {- background-color: #0F0F10 !important;- border-color: #1D1D1D !important;- }- [data-ogsc] .nf-eyebrow {- color: #a1a1aa !important;- }- [data-ogsc] .nf-callout-accent {- background-color: #fefefe !important;- }- [data-ogsc] .nf-cta {- background-color: #fefefe !important;- color: #0C0C0C !important;- border-color: #fefefe !important;- }- [data-ogsc] .nf-fallback {- color: #a1a1aa !important;- }-`;-export const ImplementationHubEmail = ({recipientName = "there",hubUrl = "https://app.carbon.ms/x/get-started"diff --git a/packages/documents/src/email/MfaEnabledEmail.tsx b/packages/documents/src/email/MfaEnabledEmail.tsxnew file mode 100644index 0000000000..7f2bd527cb--- /dev/null+++ b/packages/documents/src/email/MfaEnabledEmail.tsx@@ -0,0 +1,152 @@+import {+ Body,+ Button,+ Container,+ Heading,+ Link,+ Preview,+ Section,+ Text+} from "@react-email/components";+import { Logo } from "./components/Logo";+import { notificationStyles } from "./components/notificationStyles";+import { EmailThemeProvider, getEmailThemeClasses } from "./components/Theme";++interface Props {+ recipientName?: string;+ securityUrl: string;+}++// Sent to the person who just verified an authenticator app on their own+// account. This is an account-security receipt, not a notification — it is the+// only signal a user gets that someone enrolled a factor against their login,+// so it is sent regardless of notification preferences.+export const MfaEnabledEmail = ({+ recipientName = "there",+ securityUrl+}: Props) => {+ const themeClasses = getEmailThemeClasses();++ return (+ <EmailThemeProvider+ preview={+ <Preview>Two-factor authentication is on for your account</Preview>+ }+ additionalHeadContent={<style>{notificationStyles}</style>}+ >+ <Body+ className={`my-auto mx-auto font-sans nf-body ${themeClasses.body}`}+ >+ <Container+ className={`my-[40px] mx-auto p-[36px] max-w-[560px] rounded-[16px] nf-card ${themeClasses.container}`}+ style={{+ borderRadius: 16,+ borderStyle: "solid",+ borderWidth: 1+ }}+ >+ <Logo />++ <Text+ className={`text-[11px] leading-[16px] uppercase text-center font-medium m-0 mt-[40px] mb-[10px] nf-eyebrow ${themeClasses.mutedText}`}+ style={{ letterSpacing: "0.14em" }}+ >+ Security+ </Text>++ <Heading+ className={`text-[26px] font-medium text-center tracking-tight p-0 mt-0 mb-[32px] mx-0 ${themeClasses.heading}`}+ >+ Two-factor authentication is on+ </Heading>++ <Section>+ <Text+ className={`text-[15px] leading-[26px] m-0 mb-[16px] ${themeClasses.text}`}+ >+ Hi {recipientName ?? "there"},+ </Text>+ </Section>++ <Section+ className="nf-callout"+ style={{+ backgroundColor: "#fafafa",+ borderColor: "#ececef",+ borderRadius: 12,+ borderStyle: "solid",+ borderWidth: 1,+ marginBottom: 28,+ padding: "18px 20px"+ }}+ >+ <table+ role="presentation"+ cellPadding={0}+ cellSpacing={0}+ width="100%"+ style={{ borderCollapse: "collapse", width: "100%" }}+ >+ <tr>+ <td style={{ verticalAlign: "middle" }}>+ <Text+ className={`text-[15px] leading-[24px] m-0 ${themeClasses.text}`}+ >+ An authenticator app was added to your Carbon account.+ You'll be asked for a 6-digit code the next time you sign+ in.+ </Text>+ <Text+ className={`text-[15px] leading-[24px] m-0 mt-[12px] ${themeClasses.text}`}+ >+ If this wasn't you, remove the authenticator app from your+ security settings and tell your administrator right away.+ </Text>+ </td>+ </tr>+ </table>+ </Section>++ <Section className="text-center mb-[24px]">+ <Button+ href={securityUrl}+ className="nf-cta"+ style={{+ backgroundColor: "#0e0e0e",+ borderColor: "#0e0e0e",+ borderRadius: 10,+ borderStyle: "solid",+ borderWidth: 1,+ color: "#ffffff",+ display: "inline-block",+ fontSize: 14,+ fontWeight: 500,+ padding: "13px 24px",+ textAlign: "center",+ textDecoration: "none"+ }}+ >+ <span style={{ verticalAlign: "middle" }}>+ Review security settings+ </span>+ </Button>+ </Section>++ <Text+ className={`text-[13px] leading-[20px] m-0 text-center break-all nf-fallback ${themeClasses.mutedText}`}+ >+ Or open this link in your browser:{" "}+ <Link+ href={securityUrl}+ className={`${themeClasses.mutedText} underline nf-fallback`}+ >+ {securityUrl}+ </Link>+ </Text>+ </Container>+ </Body>+ </EmailThemeProvider>+ );+};++export default MfaEnabledEmail;diff --git a/packages/documents/src/email/MfaRequiredEmail.tsx b/packages/documents/src/email/MfaRequiredEmail.tsxnew file mode 100644index 0000000000..58759d6c59--- /dev/null+++ b/packages/documents/src/email/MfaRequiredEmail.tsx@@ -0,0 +1,152 @@+import {+ Body,+ Button,+ Container,+ Heading,+ Link,+ Preview,+ Section,+ Text+} from "@react-email/components";+import { Logo } from "./components/Logo";+import { notificationStyles } from "./components/notificationStyles";+import { EmailThemeProvider, getEmailThemeClasses } from "./components/Theme";++interface Props {+ recipientName?: string;+ companyName: string;+ setupUrl: string;+}++// Sent to every active employee of a company when an admin turns on the+// two-factor requirement. It goes to people who already have an authenticator+// app as well as those who don't — the copy covers both so enrollment status+// never has to be resolved per recipient.+export const MfaRequiredEmail = ({+ recipientName = "there",+ companyName,+ setupUrl+}: Props) => {+ const themeClasses = getEmailThemeClasses();++ return (+ <EmailThemeProvider+ preview={<Preview>Two-factor authentication is now required</Preview>}+ additionalHeadContent={<style>{notificationStyles}</style>}+ >+ <Body+ className={`my-auto mx-auto font-sans nf-body ${themeClasses.body}`}+ >+ <Container+ className={`my-[40px] mx-auto p-[36px] max-w-[560px] rounded-[16px] nf-card ${themeClasses.container}`}+ style={{+ borderRadius: 16,+ borderStyle: "solid",+ borderWidth: 1+ }}+ >+ <Logo />++ <Text+ className={`text-[11px] leading-[16px] uppercase text-center font-medium m-0 mt-[40px] mb-[10px] nf-eyebrow ${themeClasses.mutedText}`}+ style={{ letterSpacing: "0.14em" }}+ >+ Security+ </Text>++ <Heading+ className={`text-[26px] font-medium text-center tracking-tight p-0 mt-0 mb-[32px] mx-0 ${themeClasses.heading}`}+ >+ Two-factor authentication is now required+ </Heading>++ <Section>+ <Text+ className={`text-[15px] leading-[26px] m-0 mb-[16px] ${themeClasses.text}`}+ >+ Hi {recipientName ?? "there"},+ </Text>+ </Section>++ <Section+ className="nf-callout"+ style={{+ backgroundColor: "#fafafa",+ borderColor: "#ececef",+ borderRadius: 12,+ borderStyle: "solid",+ borderWidth: 1,+ marginBottom: 28,+ padding: "18px 20px"+ }}+ >+ <table+ role="presentation"+ cellPadding={0}+ cellSpacing={0}+ width="100%"+ style={{ borderCollapse: "collapse", width: "100%" }}+ >+ <tr>+ <td style={{ verticalAlign: "middle" }}>+ <Text+ className={`text-[15px] leading-[24px] m-0 ${themeClasses.text}`}+ >+ {companyName} now requires an authenticator app to sign in+ to Carbon. Set one up before your next sign-in — until you+ do, you won't be able to open {companyName} in Carbon.+ </Text>+ <Text+ className={`text-[15px] leading-[24px] m-0 mt-[12px] ${themeClasses.text}`}+ >+ Already using an authenticator app? You're all set, and+ nothing changes for you.+ </Text>+ </td>+ </tr>+ </table>+ </Section>++ <Section className="text-center mb-[24px]">+ <Button+ href={setupUrl}+ className="nf-cta"+ style={{+ backgroundColor: "#0e0e0e",+ borderColor: "#0e0e0e",+ borderRadius: 10,+ borderStyle: "solid",+ borderWidth: 1,+ color: "#ffffff",+ display: "inline-block",+ fontSize: 14,+ fontWeight: 500,+ padding: "13px 24px",+ textAlign: "center",+ textDecoration: "none"+ }}+ >+ <span style={{ verticalAlign: "middle" }}>+ Set up two-factor authentication+ </span>+ </Button>+ </Section>++ <Text+ className={`text-[13px] leading-[20px] m-0 text-center break-all nf-fallback ${themeClasses.mutedText}`}+ >+ Or open this link in your browser:{" "}+ <Link+ href={setupUrl}+ className={`${themeClasses.mutedText} underline nf-fallback`}+ >+ {setupUrl}+ </Link>+ </Text>+ </Container>+ </Body>+ </EmailThemeProvider>+ );+};++export default MfaRequiredEmail;diff --git a/packages/documents/src/email/NotificationEmail.tsx b/packages/documents/src/email/NotificationEmail.tsxindex d8b7d29a9f..99cf9f2dbb 100644--- a/packages/documents/src/email/NotificationEmail.tsx+++ b/packages/documents/src/email/NotificationEmail.tsx@@ -11,6 +11,7 @@ import {Text} from "@react-email/components";import { Logo } from "./components/Logo";+import { notificationStyles } from "./components/notificationStyles";import { EmailThemeProvider, getEmailThemeClasses } from "./components/Theme";// Structurally compatible with `NotificationDetail` from `@carbon/notifications`,@@ -41,153 +42,6 @@ interface Props {settingsUrl?: string;}-// Dark-mode-aware styles. Backgrounds are intentionally set via CSS classes-// (not inline styles) so `!important` overrides in dark-mode media queries-// can flip them — inline `style` wins against non-important CSS, but loses to-// `!important`. Most modern clients (Apple Mail, iOS Mail, Gmail web/iOS,-// Outlook web/mobile) honor this; Outlook desktop renders light-mode only,-// matching the rest of the system.-const notificationStyles = `- .nf-body {- background-color: #f5f5f7;- background-image: linear-gradient(180deg, #f5f5f7 0%, #ececef 100%);- }- .nf-card {- background-color: #ffffff;- background-image: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);- border-color: #e5e7eb;- }- .nf-divider {- border-color: #ececef !important;- }- .nf-eyebrow {- color: #6b7280 !important;- }- .nf-callout {- background-color: #fafafa !important;- border-color: #ececef !important;- }- .nf-callout-accent {- background-color: #0e0e0e !important;- }- .nf-cta {- background-color: #0e0e0e !important;- color: #ffffff !important;- border-color: #0e0e0e !important;- }- .nf-fallback {- color: #6b7280 !important;- }-- @media (prefers-color-scheme: dark) {- .nf-body {- background-color: #0C0C0C !important;- background-image: linear-gradient(180deg, #0C0C0C 0%, #161618 100%) !important;- }- .nf-card {- background-color: #161618 !important;- background-image: linear-gradient(180deg, #161618 0%, #0F0F10 100%) !important;- border-color: #1D1D1D !important;- }- .nf-divider {- border-color: #1D1D1D !important;- }- .nf-eyebrow {- color: #a1a1aa !important;- }- .nf-callout {- background-color: #0F0F10 !important;- border-color: #1D1D1D !important;- }- .nf-callout-accent {- background-color: #fefefe !important;- }- .nf-cta {- background-color: #fefefe !important;- color: #0C0C0C !important;- border-color: #fefefe !important;- }- .nf-fallback {- color: #a1a1aa !important;- }- }-- /* Gmail desktop dark mode targeting */- .gmail_dark .nf-body,- .gmail_dark_theme .nf-body,- [data-darkmode="true"] .nf-body {- background-color: #0C0C0C !important;- background-image: linear-gradient(180deg, #0C0C0C 0%, #161618 100%) !important;- }- .gmail_dark .nf-card,- .gmail_dark_theme .nf-card,- [data-darkmode="true"] .nf-card {- background-color: #161618 !important;- background-image: linear-gradient(180deg, #161618 0%, #0F0F10 100%) !important;- border-color: #1D1D1D !important;- }- .gmail_dark .nf-divider,- .gmail_dark_theme .nf-divider,- [data-darkmode="true"] .nf-divider {- border-color: #1D1D1D !important;- }- .gmail_dark .nf-eyebrow,- .gmail_dark_theme .nf-eyebrow,- [data-darkmode="true"] .nf-eyebrow {- color: #a1a1aa !important;- }- .gmail_dark .nf-callout,- .gmail_dark_theme .nf-callout,- [data-darkmode="true"] .nf-callout {- background-color: #0F0F10 !important;- border-color: #1D1D1D !important;- }- .gmail_dark .nf-callout-accent,- .gmail_dark_theme .nf-callout-accent,- [data-darkmode="true"] .nf-callout-accent {- background-color: #fefefe !important;- }- .gmail_dark .nf-cta,- .gmail_dark_theme .nf-cta,- [data-darkmode="true"] .nf-cta {- background-color: #fefefe !important;- color: #0C0C0C !important;- border-color: #fefefe !important;- }- .gmail_dark .nf-fallback,- .gmail_dark_theme .nf-fallback,- [data-darkmode="true"] .nf-fallback {- color: #a1a1aa !important;- }-- /* Outlook web/mobile dark mode targeting */- [data-ogsb] .nf-body {- background-color: #0C0C0C !important;- }- [data-ogsb] .nf-card {- background-color: #161618 !important;- border-color: #1D1D1D !important;- }- [data-ogsb] .nf-callout {- background-color: #0F0F10 !important;- border-color: #1D1D1D !important;- }- [data-ogsc] .nf-eyebrow {- color: #a1a1aa !important;- }- [data-ogsc] .nf-callout-accent {- background-color: #fefefe !important;- }- [data-ogsc] .nf-cta {- background-color: #fefefe !important;- color: #0C0C0C !important;- border-color: #fefefe !important;- }- [data-ogsc] .nf-fallback {- color: #a1a1aa !important;- }-`;-// Content props get no sample defaults — fabricated data must never reach a// real recipient. Sample data lives in the preview fixtures.export const NotificationEmail = ({diff --git a/packages/documents/src/email/components/notificationStyles.ts b/packages/documents/src/email/components/notificationStyles.tsnew file mode 100644index 0000000000..d41073ff55--- /dev/null+++ b/packages/documents/src/email/components/notificationStyles.ts@@ -0,0 +1,147 @@+// Dark-mode-aware styles shared by every card-style email (notifications and+// the standalone lifecycle emails). Backgrounds are intentionally set via CSS+// classes (not inline styles) so `!important` overrides in dark-mode media+// queries can flip them — inline `style` wins against non-important CSS, but+// loses to `!important`. Most modern clients (Apple Mail, iOS Mail, Gmail+// web/iOS, Outlook web/mobile) honor this; Outlook desktop renders light-mode+// only, matching the rest of the system.+export const notificationStyles = `+ .nf-body {+ background-color: #f5f5f7;+ background-image: linear-gradient(180deg, #f5f5f7 0%, #ececef 100%);+ }+ .nf-card {+ background-color: #ffffff;+ background-image: linear-gradient(180deg, #ffffff 0%, #fbfbfc 100%);+ border-color: #e5e7eb;+ }+ .nf-divider {+ border-color: #ececef !important;+ }+ .nf-eyebrow {+ color: #6b7280 !important;+ }+ .nf-callout {+ background-color: #fafafa !important;+ border-color: #ececef !important;+ }+ .nf-callout-accent {+ background-color: #0e0e0e !important;+ }+ .nf-cta {+ background-color: #0e0e0e !important;+ color: #ffffff !important;+ border-color: #0e0e0e !important;+ }+ .nf-fallback {+ color: #6b7280 !important;+ }++ @media (prefers-color-scheme: dark) {+ .nf-body {+ background-color: #0C0C0C !important;+ background-image: linear-gradient(180deg, #0C0C0C 0%, #161618 100%) !important;+ }+ .nf-card {+ background-color: #161618 !important;+ background-image: linear-gradient(180deg, #161618 0%, #0F0F10 100%) !important;+ border-color: #1D1D1D !important;+ }+ .nf-divider {+ border-color: #1D1D1D !important;+ }+ .nf-eyebrow {+ color: #a1a1aa !important;+ }+ .nf-callout {+ background-color: #0F0F10 !important;+ border-color: #1D1D1D !important;+ }+ .nf-callout-accent {+ background-color: #fefefe !important;+ }+ .nf-cta {+ background-color: #fefefe !important;+ color: #0C0C0C !important;+ border-color: #fefefe !important;+ }+ .nf-fallback {+ color: #a1a1aa !important;+ }+ }++ /* Gmail desktop dark mode targeting */+ .gmail_dark .nf-body,+ .gmail_dark_theme .nf-body,+ [data-darkmode="true"] .nf-body {+ background-color: #0C0C0C !important;+ background-image: linear-gradient(180deg, #0C0C0C 0%, #161618 100%) !important;+ }+ .gmail_dark .nf-card,+ .gmail_dark_theme .nf-card,+ [data-darkmode="true"] .nf-card {+ background-color: #161618 !important;+ background-image: linear-gradient(180deg, #161618 0%, #0F0F10 100%) !important;+ border-color: #1D1D1D !important;+ }+ .gmail_dark .nf-divider,+ .gmail_dark_theme .nf-divider,+ [data-darkmode="true"] .nf-divider {+ border-color: #1D1D1D !important;+ }+ .gmail_dark .nf-eyebrow,+ .gmail_dark_theme .nf-eyebrow,+ [data-darkmode="true"] .nf-eyebrow {+ color: #a1a1aa !important;+ }+ .gmail_dark .nf-callout,+ .gmail_dark_theme .nf-callout,+ [data-darkmode="true"] .nf-callout {+ background-color: #0F0F10 !important;+ border-color: #1D1D1D !important;+ }+ .gmail_dark .nf-callout-accent,+ .gmail_dark_theme .nf-callout-accent,+ [data-darkmode="true"] .nf-callout-accent {+ background-color: #fefefe !important;+ }+ .gmail_dark .nf-cta,+ .gmail_dark_theme .nf-cta,+ [data-darkmode="true"] .nf-cta {+ background-color: #fefefe !important;+ color: #0C0C0C !important;+ border-color: #fefefe !important;+ }+ .gmail_dark .nf-fallback,+ .gmail_dark_theme .nf-fallback,+ [data-darkmode="true"] .nf-fallback {+ color: #a1a1aa !important;+ }++ /* Outlook web/mobile dark mode targeting */+ [data-ogsb] .nf-body {+ background-color: #0C0C0C !important;+ }+ [data-ogsb] .nf-card {+ background-color: #161618 !important;+ border-color: #1D1D1D !important;+ }+ [data-ogsb] .nf-callout {+ background-color: #0F0F10 !important;+ border-color: #1D1D1D !important;+ }+ [data-ogsc] .nf-eyebrow {+ color: #a1a1aa !important;+ }+ [data-ogsc] .nf-callout-accent {+ background-color: #fefefe !important;+ }+ [data-ogsc] .nf-cta {+ background-color: #fefefe !important;+ color: #0C0C0C !important;+ border-color: #fefefe !important;+ }+ [data-ogsc] .nf-fallback {+ color: #a1a1aa !important;+ }+`;diff --git a/packages/documents/src/email/index.ts b/packages/documents/src/email/index.tsindex cbcce6bf34..8424dca855 100644--- a/packages/documents/src/email/index.ts+++ b/packages/documents/src/email/index.ts@@ -1,6 +1,8 @@import GetStartedEmail from "./GetStartedEmail";import ImplementationHubEmail from "./ImplementationHubEmail";import InviteEmail from "./InviteEmail";+import MfaEnabledEmail from "./MfaEnabledEmail";+import MfaRequiredEmail from "./MfaRequiredEmail";import NotificationEmail from "./NotificationEmail";import PurchaseOrderEmail from "./PurchaseOrderEmail";import QuoteEmail from "./QuoteEmail";@@ -20,6 +22,8 @@ export {GetStartedEmail,ImplementationHubEmail,InviteEmail,+ MfaEnabledEmail,+ MfaRequiredEmail,NotificationEmail,PurchaseOrderEmail,QuoteEmail,diff --git a/packages/documents/src/email/previews/MfaEnabledEmail.tsx b/packages/documents/src/email/previews/MfaEnabledEmail.tsxnew file mode 100644index 0000000000..2522a8590f--- /dev/null+++ b/packages/documents/src/email/previews/MfaEnabledEmail.tsx@@ -0,0 +1,10 @@+import MfaEnabledEmail from "../MfaEnabledEmail";++export default function MfaEnabledEmailPreview() {+ return (+ <MfaEnabledEmail+ recipientName={"Jane Doe"}+ securityUrl={"https://app.carbon.ms/x/account/security"}+ />+ );+}diff --git a/packages/documents/src/email/previews/MfaRequiredEmail.tsx b/packages/documents/src/email/previews/MfaRequiredEmail.tsxnew file mode 100644index 0000000000..2db061eeec--- /dev/null+++ b/packages/documents/src/email/previews/MfaRequiredEmail.tsx@@ -0,0 +1,11 @@+import MfaRequiredEmail from "../MfaRequiredEmail";++export default function MfaRequiredEmailPreview() {+ return (+ <MfaRequiredEmail+ recipientName={"John Doe"}+ companyName={"Acme Manufacturing"}+ setupUrl={"https://app.carbon.ms/x/account/security"}+ />+ );+}