Skip to content

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.

feat(dev): add Email previews app to crbn up with one-page email gallery (#1231)

Naveen Kashyap347caa4923bf
diff --git a/packages/dev/AGENTS.md b/packages/dev/AGENTS.md
index af16e1ab1e..149caadb04 100644
--- a/packages/dev/AGENTS.md
+++ b/packages/dev/AGENTS.md
@@ -35,6 +35,7 @@ pnpm --filter @carbon/dev typecheck # tsgo --noEmit
- **Provision** (`commands/init.ts`): `crbn init` provisions an already-created worktree (canonical slug + env sync + skills) to match a `crbn checkout`; shared by `new`, the bash `checkout` post-create hook, and Conductor's `setup` (`.conductor/settings.toml`). It does NOT boot the stack — `crbn up` still mints ports/`.env.local`.
- **Worktree** (`worktree.ts`): `resolveSlug()`, `canonicalSlug()` (branch-derived `<repoBase>-<branch>`), `getWorktreeRoot()`, `projectName()`, `ensureSlugAvailable()`
- **Services**: `compose.ts` (Docker), `migrations.ts` (Postgres/Supabase), `portless.ts` (`.dev` URLs), `apps.ts` (dev servers)
+- **Aux spawners** (`services/apps.ts`): `spawnAssembler` (cargo) and `spawnEmailPreview` (`@carbon/documents` `email:previews` on `PORT_EMAIL` — the react-email server over `src/email/previews`, one fixture per email) — opt-in picker apps with their own spawners, not react-router dev servers
- **Env**: `env.ts` — `renderEnv()`, `writeEnv()`, `syncAppPortlessConfigs()`
- **`--run` flag**: scopes stack lifetime to a command (for headless/CI builds); `--volumes` cleans up Docker volumes on teardown
diff --git a/packages/dev/README.md b/packages/dev/README.md
index 7c8bd0f0ba..7217b4682c 100644
--- a/packages/dev/README.md
+++ b/packages/dev/README.md
@@ -27,7 +27,8 @@ source ./setup.sh # adds crbn to PATH + installs shell wrapper
| Command | Description |
|---|---|
-| `crbn up` | Boot compose stack + apps. |
+| `crbn up` | Boot compose stack + apps. Picker includes opt-in apps: Assembler, Email previews (react-email server for every email template at `email.<branch>.dev`). |
+| `crbn up --all` | Launch all apps without the picker (ERP, MES, email previews; assembler when its OCCT build exists). |
| `crbn up --no-portless` | Localhost mode: fixed ports (API `:54321`, ERP `:3000`, MES `:3001`). |
| `crbn up --borrow` | Reuse another worktree's running containers (DB, API, etc). |
| `crbn up --no-apps` | Services only (postgres, kong, supabase, inngest, mail). |
@@ -39,6 +40,10 @@ source ./setup.sh # adds crbn to PATH + installs shell wrapper
| `crbn status` | Port assignment + container health. |
| `crbn migrate` | Apply DB migrations against the running stack. |
+`CARBON_DEV_APPS` skips the picker: `CARBON_DEV_APPS=erp,mes,email crbn up`.
+Comma-separated, from `erp`, `mes`, `assembler`, `email` — unrecognized names
+are dropped silently. Shell-level only; it is not read from `.env.local`.
+
### Files
| Command | Description |
diff --git a/packages/dev/src/commands/up.ts b/packages/dev/src/commands/up.ts
index ff8b4d5cbf..e14a69daf3 100644
--- a/packages/dev/src/commands/up.ts
+++ b/packages/dev/src/commands/up.ts
@@ -14,8 +14,11 @@ import {
installSkills,
spawnApps,
spawnAssembler,
+ spawnEmailPreview,
spawnStripeListener,
- syncEnvSymlinks
+ stopAuxApps,
+ syncEnvSymlinks,
+ whenAuxAppExits
} from "../services/apps.js";
import {
allImagesPresentLocally,
@@ -254,6 +257,10 @@ export async function up(opts: UpOpts = {}) {
spawnAssembler({ root, ports: ctx.ports });
}
+ if (selectedApps.includes("email")) {
+ spawnEmailPreview({ root, ports: ctx.ports });
+ }
+
const summary = summaryLines(
ctx.ports,
selectedApps,
@@ -388,7 +395,8 @@ async function provisionSlot(
ports: {
...borrowedEntry.ports,
PORT_ERP: ownSlot.ports.PORT_ERP,
- PORT_MES: ownSlot.ports.PORT_MES
+ PORT_MES: ownSlot.ports.PORT_MES,
+ PORT_EMAIL: ownSlot.ports.PORT_EMAIL
} as PortMap,
redisDb: borrowedEntry.redisDb,
jwt: borrowedEntry.jwt
@@ -679,6 +687,10 @@ async function ensureHostsFile() {
await syncHostsFile();
}
+function reactRouterApps(selectedApps: AppId[]): AppId[] {
+ return selectedApps.filter((id) => id !== "assembler" && id !== "email");
+}
+
async function runAppsThenTeardown(
root: string,
selectedApps: AppId[],
@@ -686,8 +698,17 @@ async function runAppsThenTeardown(
portless: boolean,
stripeChild?: ExecaChildProcess
) {
- const reactRouterApps = selectedApps.filter((id) => id !== "assembler");
- await spawnApps({ root, apps: reactRouterApps, ports, portless });
+ const apps = reactRouterApps(selectedApps);
+ if (apps.length === 0) {
+ await Promise.race([
+ new Promise<void>((resolve) => {
+ onShutdown(() => resolve());
+ }),
+ whenAuxAppExits()
+ ]);
+ } else {
+ await spawnApps({ root, apps, ports, portless });
+ }
// Apps exit on Ctrl+C; auto-`down` so compose stack isn't orphaned.
// Swallow further signals so a second Ctrl+C during teardown doesn't
@@ -768,7 +789,7 @@ async function runAppsThenCommand(
const controller = new AbortController();
const appsDone = spawnApps({
root,
- apps: selectedApps,
+ apps: reactRouterApps(selectedApps),
ports,
portless,
signal: controller.signal
@@ -790,6 +811,7 @@ async function runAppsThenCommand(
} finally {
controller.abort(); // stop the app supervisors
await appsDone;
+ stopAuxApps();
killStripe(stripeChild);
await down({ silent: true, volumes: cleanVolumes });
detach();
diff --git a/packages/dev/src/constants.ts b/packages/dev/src/constants.ts
index 644f59c2fc..b9755bcf40 100644
--- a/packages/dev/src/constants.ts
+++ b/packages/dev/src/constants.ts
@@ -16,6 +16,11 @@ export const APP_CHOICES = [
value: "assembler",
label: "Assembler",
hint: "CAD convert + motion planning"
+ },
+ {
+ value: "email",
+ label: "Email previews",
+ hint: "react-email server for every email template"
}
] as const;
export type AppId = (typeof APP_CHOICES)[number]["value"];
diff --git a/packages/dev/src/env.test.ts b/packages/dev/src/env.test.ts
index 58d1dab84e..10bede114d 100644
--- a/packages/dev/src/env.test.ts
+++ b/packages/dev/src/env.test.ts
@@ -10,7 +10,8 @@ const ports: PortMap = {
PORT_INNGEST: 54004,
PORT_ERP: 54005,
PORT_MES: 54006,
- PORT_ASSEMBLER: 54007
+ PORT_ASSEMBLER: 54007,
+ PORT_EMAIL: 54008
};
const jwt: JwtCreds = {
@@ -65,6 +66,8 @@ describe("renderEnv (portless disabled)", () => {
expect(out).toContain("PORT_INNGEST=54004");
expect(out).toContain("PORT_ERP=54005");
expect(out).toContain("PORT_MES=54006");
+ expect(out).toContain("PORT_EMAIL=54008");
+ expect(out).toContain("EMAIL_DEV_PORT=54008");
});
it("places redis db index in REDIS_URL", () => {
@@ -136,6 +139,8 @@ describe("renderEnv (portless enabled)", () => {
expect(out).toContain("PORT_INNGEST=54004");
expect(out).toContain("PORT_ERP=54005");
expect(out).toContain("PORT_MES=54006");
+ expect(out).toContain("PORT_EMAIL=54008");
+ expect(out).toContain("EMAIL_DEV_PORT=54008");
});
it("places redis db index in REDIS_URL", () => {
diff --git a/packages/dev/src/env.ts b/packages/dev/src/env.ts
index ee0bb65164..1fe6afd1cb 100644
--- a/packages/dev/src/env.ts
+++ b/packages/dev/src/env.ts
@@ -118,6 +118,7 @@ export function renderEnv(opts: {
// which is why we can't reuse ${DOMAIN} (e.g. `main.dev` won't match the
// `erp.main.dev` host the SDK URL points at).
lines.push(`INNGEST_TLS_HOST=${portless ? host("erp") : "localhost"}`);
+ lines.push(`EMAIL_DEV_PORT=${ports.PORT_EMAIL}`);
lines.push("");
if (includeAssembler) {
lines.push("# Assembler service (CAD conversion + motion planning)");
diff --git a/packages/dev/src/prompts.ts b/packages/dev/src/prompts.ts
index 7bc44c7bdc..b230dbd38c 100644
--- a/packages/dev/src/prompts.ts
+++ b/packages/dev/src/prompts.ts
@@ -56,11 +56,10 @@ export async function pickApps(): Promise<AppId[]> {
.map((s) => s.trim())
.filter((s): s is AppId => APP_CHOICES.some((c) => c.value === s));
}
- // The assembler is opt-in: it needs a one-time native OCCT build, so it's
- // never selected by default — only via CARBON_DEV_APPS or an explicit check.
- const defaultApps = APP_CHOICES.filter((c) => c.value !== "assembler").map(
- (c) => c.value
- );
+ const optInApps: readonly AppId[] = ["assembler", "email"];
+ const defaultApps = APP_CHOICES.filter(
+ (c) => !optInApps.includes(c.value)
+ ).map((c) => c.value);
if (!process.stdin.isTTY) return defaultApps;
note(
diff --git a/packages/dev/src/services/apps.test.ts b/packages/dev/src/services/apps.test.ts
index 89bb01ddef..c2a541b343 100644
--- a/packages/dev/src/services/apps.test.ts
+++ b/packages/dev/src/services/apps.test.ts
@@ -10,7 +10,12 @@ import { tmpdir } from "node:os";
import { join } from "pathe";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { PortMap } from "../worktree.js";
-import { spawnApps } from "./apps.js";
+import {
+ spawnApps,
+ spawnEmailPreview,
+ stopAuxApps,
+ whenAuxAppExits
+} from "./apps.js";
// A stand-in "dev server": a real child process we can make crash on demand.
// It appends its app id to a shared log on every launch (so the test can count
@@ -175,3 +180,48 @@ describe("spawnApps supervisor (integration)", () => {
expect(elapsed).toBeGreaterThanOrEqual(3_400);
}, 20_000);
});
+
+describe("aux app lifecycle", () => {
+ let root: string;
+ let script: string;
+
+ beforeEach(() => {
+ root = mkdtempSync(join(tmpdir(), "carbon-aux-"));
+ mkdirSync(join(root, "packages", "documents"), { recursive: true });
+ script = join(root, "aux.cjs");
+ writeFileSync(script, "setInterval(() => {}, 1 << 30);\n");
+ });
+
+ afterEach(() => {
+ stopAuxApps();
+ rmSync(root, { recursive: true, force: true });
+ });
+
+ const spawnFake = (args: string[] = [script]) =>
+ spawnEmailPreview({
+ root,
+ ports: { PORT_EMAIL: 39003 } as unknown as PortMap,
+ command: () => ({ file: process.execPath, args })
+ });
+
+ it("stopAuxApps kills a running aux child (the --run teardown path)", async () => {
+ const child = spawnFake();
+ await waitFor(() => typeof child.pid === "number");
+ expect(child.exitCode).toBeNull();
+
+ stopAuxApps();
+
+ await waitFor(() => child.exitCode !== null || child.signalCode !== null);
+ expect(child.killed || child.signalCode !== null).toBe(true);
+ }, 20_000);
+
+ it("whenAuxAppExits resolves when an aux child dies on its own", async () => {
+ const exited = (async () => {
+ const child = spawnFake(["-e", "setTimeout(() => process.exit(3), 150)"]);
+ await waitFor(() => typeof child.pid === "number");
+ return whenAuxAppExits();
+ })();
+
+ await expect(exited).resolves.toBeUndefined();
+ }, 20_000);
+});
diff --git a/packages/dev/src/services/apps.ts b/packages/dev/src/services/apps.ts
index 04271c9261..6c0cbfbaf8 100644
--- a/packages/dev/src/services/apps.ts
+++ b/packages/dev/src/services/apps.ts
@@ -260,6 +260,33 @@ export function assertAssemblerDepsBuilt(): void {
}
}
+const auxChildren = new Set<ExecaChildProcess>();
+
+function trackAuxChild(child: ExecaChildProcess): void {
+ auxChildren.add(child);
+ child.once("exit", () => auxChildren.delete(child));
+}
+
+export function stopAuxApps(): void {
+ for (const child of auxChildren) {
+ if (child.exitCode !== null || !child.pid) continue;
+ try {
+ process.kill(-child.pid, "SIGTERM");
+ } catch {
+ try {
+ child.kill("SIGTERM");
+ // biome-ignore lint/suspicious/noEmptyBlockStatements: best-effort kill
+ } catch {}
+ }
+ }
+}
+
+export function whenAuxAppExits(): Promise<void> {
+ return new Promise<void>((resolve) => {
+ for (const child of auxChildren) child.once("exit", () => resolve());
+ });
+}
+
export function spawnAssembler(opts: {
root: string;
ports: PortMap;
@@ -320,17 +347,63 @@ export function spawnAssembler(opts: {
pipe(child.stdout, process.stdout);
pipe(child.stderr, process.stderr);
- onShutdown(() => {
- if (child.exitCode !== null || !child.pid) return;
- try {
- process.kill(-child.pid, "SIGTERM");
- } catch {
- try {
- child.kill("SIGTERM");
- } catch {}
- }
+ trackAuxChild(child);
+ onShutdown(() => stopAuxApps());
+
+ return child;
+}
+
+const EMAIL_PREFIX = pc.green(pc.bold("eml | "));
+
+const EMAIL_STARTUP_PATTERNS: RegExp[] = [
+ /^\s*React Email\b/,
+ /^\s*Running preview at:/,
+ /Getting react-email preview server ready/,
+ /^\s*[✔✓]\s*Ready in\b/
+];
+
+function isEmailStartupLine(line: string): boolean {
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: strip SGR codes
+ const plain = line.replace(/\x1b\[[0-9;]*m/g, "");
+ return EMAIL_STARTUP_PATTERNS.some((re) => re.test(plain));
+}
+
+export function spawnEmailPreview(opts: {
+ root: string;
+ ports: PortMap;
+ command?: () => { file: string; args: string[] };
+}): ExecaChildProcess {
+ const { root, ports, command } = opts;
+ const port = ports.PORT_EMAIL;
+ const { file, args } = command?.() ?? {
+ file: "pnpm",
+ args: ["run", "email:previews"]
+ };
+
+ const child = execa(file, args, {
+ cwd: join(root, "packages", "documents"),
+ env: { ...process.env, EMAIL_DEV_PORT: String(port) },
+ reject: false,
+ stdin: "ignore",
+ detached: true
});
+ const pipe = (
+ stream: NodeJS.ReadableStream | null,
+ sink: NodeJS.WriteStream
+ ) => {
+ if (!stream) return;
+ readLines(stream, (line) => {
+ if (isNoiseLine(line) || isEmailStartupLine(line)) return;
+ sink.write(`${EMAIL_PREFIX}${line}\n`);
+ });
+ };
+ pipe(child.stdout, process.stdout);
+ pipe(child.stderr, process.stderr);
+
+ trackAuxChild(child);
+ onShutdown(() => stopAuxApps());
+
return child;
}
@@ -410,7 +483,9 @@ export async function installSkills(root: string): Promise<boolean> {
// reliable since ports are unique per worktree (allocated in the slot
// registry). Best-effort — silently skips ports with nothing listening.
export async function killOrphanedApps(ports: PortMap): Promise<void> {
- const appPorts = [ports.PORT_ERP, ports.PORT_MES];
+ const appPorts = [ports.PORT_ERP, ports.PORT_MES, ports.PORT_EMAIL].filter(
+ (p) => typeof p === "number"
+ );
for (const port of appPorts) {
const r = await execa("lsof", ["-ti", `:${port}`], { reject: false });
if (r.exitCode !== 0) continue;
diff --git a/packages/dev/src/services/portless.ts b/packages/dev/src/services/portless.ts
index 789f9e37fa..fb2ae6fd9a 100644
--- a/packages/dev/src/services/portless.ts
+++ b/packages/dev/src/services/portless.ts
@@ -419,6 +419,7 @@ function aliasMap(
{ name: withPrefix("api", branchPrefix), port: ports.PORT_API },
{ name: withPrefix("studio", branchPrefix), port: ports.PORT_STUDIO },
{ name: withPrefix("mail", branchPrefix), port: ports.PORT_INBUCKET },
+ { name: withPrefix("email", branchPrefix), port: ports.PORT_EMAIL },
{ name: withPrefix("inngest", branchPrefix), port: ports.PORT_INNGEST },
{ name: withPrefix("assembler", branchPrefix), port: ports.PORT_ASSEMBLER },
{ name: STABLE_OAUTH_ALIAS, port: ports.PORT_API }
diff --git a/packages/dev/src/ui.ts b/packages/dev/src/ui.ts
index dfb26b81f5..502849d949 100644
--- a/packages/dev/src/ui.ts
+++ b/packages/dev/src/ui.ts
@@ -36,7 +36,7 @@ export function portsTable(
for (const n of PORT_NAMES) {
t.push([
pc.cyan(n.replace("PORT_", "").toLowerCase()),
- pc.bold(String(ports[n]))
+ ports[n] === undefined ? pc.dim("—") : pc.bold(String(ports[n]))
]);
}
t.push([
@@ -161,6 +161,16 @@ export function summaryLines(
url("mail", ports.PORT_INBUCKET),
branchPrefix ? ports.PORT_INBUCKET : undefined
),
+ ...(apps.includes("email")
+ ? [
+ row(
+ pc.yellow,
+ "Email",
+ url("email", ports.PORT_EMAIL),
+ branchPrefix ? ports.PORT_EMAIL : undefined
+ )
+ ]
+ : []),
row(
pc.blue,
"Inngest",
diff --git a/packages/dev/src/worktree.ts b/packages/dev/src/worktree.ts
index 361ad9bc7c..7d740c6eba 100644
--- a/packages/dev/src/worktree.ts
+++ b/packages/dev/src/worktree.ts
@@ -23,10 +23,13 @@ export const PORT_NAMES = [
"PORT_INNGEST",
"PORT_ERP",
"PORT_MES",
- "PORT_ASSEMBLER"
+ "PORT_ASSEMBLER",
+ "PORT_EMAIL"
] as const;
type PortName = (typeof PORT_NAMES)[number];
+const OPTIONAL_PORT_NAMES: readonly PortName[] = ["PORT_EMAIL"];
+
export type PortMap = Record<PortName, number>;
export type JwtCreds = { secret: string; anonKey: string; serviceKey: string };
type RegistryEntry = {
@@ -158,6 +161,7 @@ export async function resolveSlot(
// Fast path: registry entry is valid, points at this worktree, and all
// ports are still available (no stale processes holding them).
if (existing && sameWorktreePath(existing.worktreeRoot, worktreeRoot)) {
+ await backfillMissingPorts(registry, slug, existing);
const allFree = await portsAvailable(Object.values(existing.ports));
if (allFree) {
return {
@@ -182,6 +186,23 @@ export async function resolveSlot(
return { ports, redisDb, jwt };
}
+async function backfillMissingPorts(
+ registry: Registry,
+ slug: string,
+ entry: RegistryEntry
+): Promise<void> {
+ const missing = OPTIONAL_PORT_NAMES.filter(
+ (n) => entry.ports[n] === undefined
+ );
+ if (missing.length === 0) return;
+ const { claimedPorts } = collectClaims(registry, slug);
+ for (const p of Object.values(entry.ports)) claimedPorts.add(p);
+ for (const name of missing) {
+ entry.ports[name] = await pickFreePort(claimedPorts);
+ }
+ writeRegistry(registry);
+}
+
function collectClaims(
registry: Registry,
excludeSlug: string
@@ -274,6 +295,7 @@ function isPortMap(v: unknown): v is PortMap {
if (!v || typeof v !== "object") return false;
const o = v as Record<string, unknown>;
for (const name of PORT_NAMES) {
+ if (o[name] === undefined && OPTIONAL_PORT_NAMES.includes(name)) continue;
if (typeof o[name] !== "number" || !Number.isInteger(o[name])) return false;
}
return true;
diff --git a/packages/documents/AGENTS.md b/packages/documents/AGENTS.md
index 1863dd64c3..ec19f6caf2 100644
--- a/packages/documents/AGENTS.md
+++ b/packages/documents/AGENTS.md
@@ -35,6 +35,7 @@ pnpm --filter @carbon/documents build # generates fonts.data.ts
- **Two PDF styles**: block-registry driven (customizable) vs hand-built (fixed layout labels)
- **Block shape**: `({ block, data }) => JSX.Element | null`, keyed in per-doc `registry.tsx`
- **Fonts**: bundled as base64 woff in gitignored `pdf/fonts.data.ts`, generated by `scripts/generate-fonts.mjs`
+- **Email previews**: `src/email/previews/` holds **one fixture per shipped email** — every `NotificationEvent` that sends mail (except `Digest`, which is in-app only), plus the transactional and lifecycle templates. Fixtures are not shipped (not exported from `index.ts`). `pnpm email:previews` is the only way to view them — it serves the react-email dev server over that folder on `EMAIL_DEV_PORT`, and is what `crbn up`'s Email app runs. Point `email-dev.mjs` at `./src/email` by hand if you ever need the bare templates, but the four document emails error there (their props are DB view rows). The per-event `NotificationEmail` fixtures are generated: edit the `previews` array in `scripts/generate-notification-previews.mjs`, re-run it, then `biome check --write` the folder (the generator emits raw JSON indentation)
- **Exports**: `./pdf`, `./email`, `./template`, `./zpl`, `./qr`, `./labels`
## Cross-References
diff --git a/packages/documents/package.json b/packages/documents/package.json
index 539061b47c..a5358cfacb 100644
--- a/packages/documents/package.json
+++ b/packages/documents/package.json
@@ -51,7 +51,6 @@
"scripts": {
"build": "node ./scripts/generate-fonts.mjs",
"clean": "rimraf .turbo node_modules dist",
- "email": "node ./scripts/email-dev.mjs ./src/email",
"email:previews": "node ./scripts/email-dev.mjs ./src/email/previews",
"lint": "biome lint --write ",
"test": "vitest run",
diff --git a/packages/documents/scripts/email-dev.mjs b/packages/documents/scripts/email-dev.mjs
index bbd0dcabc2..9f1ede10f7 100644
--- a/packages/documents/scripts/email-dev.mjs
+++ b/packages/documents/scripts/email-dev.mjs
@@ -8,26 +8,14 @@ import { fileURLToPath } from "node:url";
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
// loadEnvFile never overwrites existing keys — .env.local first so it wins.
-const loadedEnvFiles = [];
for (const file of [".env.local", ".env"]) {
const path = resolve(repoRoot, file);
- if (existsSync(path)) {
- process.loadEnvFile(path);
- loadedEnvFiles.push(file);
- }
+ if (existsSync(path)) process.loadEnvFile(path);
}
-const [dir = "./src/email"] = process.argv.slice(2);
+const [dir = "./src/email/previews"] = process.argv.slice(2);
const port = process.env.EMAIL_DEV_PORT || "3030";
-console.log(`
- Email preview server
- ➜ URL: http://localhost:${port}
- ➜ Templates: ${dir}
- ➜ Env files: ${loadedEnvFiles.join(", ") || "none found"}
- ➜ ERP_URL: ${process.env.ERP_URL || "(not set — asset URLs will be broken)"}
-`);
-
const result = spawnSync("email", ["dev", "--dir", dir, "--port", port], {
stdio: "inherit"
});
diff --git a/packages/documents/scripts/generate-notification-previews.mjs b/packages/documents/scripts/generate-notification-previews.mjs
index e760562da2..2366f6d7b1 100644
--- a/packages/documents/scripts/generate-notification-previews.mjs
+++ b/packages/documents/scripts/generate-notification-previews.mjs
@@ -406,6 +406,19 @@ const previews = [
{ label: "Approved by", value: "Tom Sawyer" }
]
},
+ {
+ name: "PurchasingRfqAssignment",
+ heading: "Purchasing RFQ assigned to you",
+ message: "Purchasing RFQ PRFQ-0004 assigned to you",
+ reference: "PRFQ-0004",
+ cta: "View details",
+ url: "https://app.carbon.ms/x/purchasing-rfq/1",
+ details: [
+ { label: "RFQ date", value: "Jul 6, 2026" },
+ { label: "Expires", value: "Aug 14, 2026" },
+ { label: "Status", value: "Requested" }
+ ]
+ },
{
name: "ChangeOrderStarted",
heading: "Change order started",
diff --git a/packages/documents/src/email/previews/GetStartedEmail.tsx b/packages/documents/src/email/previews/GetStartedEmail.tsx
new file mode 100644
index 0000000000..02e626d9c0
--- /dev/null
+++ b/packages/documents/src/email/previews/GetStartedEmail.tsx
@@ -0,0 +1,10 @@
+import GetStartedEmail from "../GetStartedEmail";
+
+export default function GetStartedEmailPreview() {
+ return (
+ <GetStartedEmail
+ firstName={"John"}
+ academyUrl={"https://learn.carbon.ms"}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/ImplementationHubEmail.tsx b/packages/documents/src/email/previews/ImplementationHubEmail.tsx
new file mode 100644
index 0000000000..4779e5aca0
--- /dev/null
+++ b/packages/documents/src/email/previews/ImplementationHubEmail.tsx
@@ -0,0 +1,10 @@
+import ImplementationHubEmail from "../ImplementationHubEmail";
+
+export default function ImplementationHubEmailPreview() {
+ return (
+ <ImplementationHubEmail
+ recipientName={"John Doe"}
+ hubUrl={"https://app.carbon.ms/x/get-started"}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/InviteEmail.tsx b/packages/documents/src/email/previews/InviteEmail.tsx
new file mode 100644
index 0000000000..7bf1d5ada1
--- /dev/null
+++ b/packages/documents/src/email/previews/InviteEmail.tsx
@@ -0,0 +1,16 @@
+import InviteEmail from "../InviteEmail";
+
+export default function InviteEmailPreview() {
+ return (
+ <InviteEmail
+ email={"[email protected]"}
+ name={"John Doe"}
+ invitedByEmail={"[email protected]"}
+ invitedByName={"Tom Sawyer"}
+ companyName={"Tombstone Machine Works"}
+ inviteLink={"https://app.carbon.ms/invite/a1b2c3d4e5f6"}
+ ip={"73.162.44.10"}
+ location={"Austin, TX"}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/PurchaseOrderEmail.tsx b/packages/documents/src/email/previews/PurchaseOrderEmail.tsx
new file mode 100644
index 0000000000..e3206a9670
--- /dev/null
+++ b/packages/documents/src/email/previews/PurchaseOrderEmail.tsx
@@ -0,0 +1,118 @@
+import type { Database } from "@carbon/database";
+import PurchaseOrderEmail from "../PurchaseOrderEmail";
+
+const company = {
+ name: "Tombstone Machine Works",
+ logoLightIcon: null,
+ baseCurrencyCode: "USD"
+} as unknown as Database["public"]["Views"]["companies"]["Row"];
+
+const purchaseOrder = {
+ purchaseOrderId: "PO-00099",
+ paymentTermId: "payment-term-net-30",
+ receiptRequestedDate: "2026-08-14",
+ externalNotes: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [
+ {
+ type: "text",
+ text: "Please include material certs with the shipment and reference PO-00099 on all packing slips."
+ }
+ ]
+ }
+ ]
+ }
+} as unknown as Database["public"]["Views"]["purchaseOrders"]["Row"];
+
+const purchaseOrderLines = [
+ {
+ id: "po-line-1",
+ purchaseOrderLineType: "Part",
+ supplierPartId: "GLX-6061-BRKT",
+ supplierPartIdFromSupplier: null,
+ itemReadableId: "BRKT-6061",
+ description: "6061-T6 Aluminum Bracket",
+ itemDescription: "CNC machined, clear anodize per MIL-A-8625 Type II",
+ purchaseQuantity: 25,
+ purchaseUnitOfMeasureCode: "EA",
+ unitPrice: 42.5,
+ supplierUnitPrice: 42.5,
+ supplierShippingCost: 0,
+ supplierTaxAmount: 0
+ },
+ {
+ id: "po-line-2",
+ purchaseOrderLineType: "Part",
+ supplierPartId: "",
+ supplierPartIdFromSupplier: null,
+ itemReadableId: "FAS-M8-125",
+ description: "M8x1.25 Hex Bolt",
+ itemDescription: "Class 10.9, zinc plated, 30mm length",
+ purchaseQuantity: 500,
+ purchaseUnitOfMeasureCode: "EA",
+ unitPrice: 0.18,
+ supplierUnitPrice: 0.18,
+ supplierShippingCost: 12.5,
+ supplierTaxAmount: 0
+ },
+ {
+ id: "po-line-3",
+ purchaseOrderLineType: "Comment",
+ supplierPartId: null,
+ supplierPartIdFromSupplier: null,
+ itemReadableId: null,
+ description:
+ "Partial shipments accepted. Contact purchasing before substituting alloys.",
+ itemDescription: null,
+ purchaseQuantity: null,
+ purchaseUnitOfMeasureCode: null,
+ unitPrice: null,
+ supplierUnitPrice: null,
+ supplierShippingCost: null,
+ supplierTaxAmount: null
+ }
+] as unknown as Database["public"]["Views"]["purchaseOrderLines"]["Row"][];
+
+const purchaseOrderLocations = {
+ deliveryName: "Tombstone Machine Works — Plant 1",
+ deliveryAddressLine1: "4501 Foundry Road",
+ deliveryAddressLine2: "Dock B",
+ deliveryCity: "Tombstone",
+ deliveryStateProvince: "AZ",
+ deliveryPostalCode: "85638",
+ deliveryCountryName: "United States",
+ dropShipment: false,
+ customerName: null,
+ customerAddressLine1: null,
+ customerAddressLine2: null,
+ customerCity: null,
+ customerStateProvince: null,
+ customerPostalCode: null,
+ customerCountryName: null
+} as unknown as Database["public"]["Views"]["purchaseOrderLocations"]["Row"];
+
+export default function PurchaseOrderEmailPreview() {
+ return (
+ <PurchaseOrderEmail
+ company={company}
+ locale="en-US"
+ purchaseOrder={purchaseOrder}
+ purchaseOrderLines={purchaseOrderLines}
+ purchaseOrderLocations={purchaseOrderLocations}
+ paymentTerms={[{ id: "payment-term-net-30", name: "Net 30" }]}
+ recipient={{
+ firstName: "Tom",
+ lastName: "Sawyer",
+ }}
+ sender={{
+ firstName: "Jane",
+ lastName: "Doe",
+ }}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/PurchasingRfqAssignment.tsx b/packages/documents/src/email/previews/PurchasingRfqAssignment.tsx
new file mode 100644
index 0000000000..34503e27c1
--- /dev/null
+++ b/packages/documents/src/email/previews/PurchasingRfqAssignment.tsx
@@ -0,0 +1,31 @@
+import { NotificationEmail } from "../NotificationEmail";
+
+// Preview fixture — mirrors what getNotificationContent builds for the
+// PurchasingRfqAssignment event. Not shipped (not exported from index.ts).
+export default function PurchasingRfqAssignmentPreview() {
+ return (
+ <NotificationEmail
+ heading={"Purchasing RFQ assigned to you"}
+ preview={"Purchasing RFQ assigned to you"}
+ message={"Purchasing RFQ PRFQ-0004 assigned to you"}
+ reference={"PRFQ-0004"}
+ recipientName={"John Doe"}
+ ctaLabel={"View details"}
+ ctaUrl={"https://app.carbon.ms/x/purchasing-rfq/1"}
+ details={[
+ {
+ label: "RFQ date",
+ value: "Jul 6, 2026"
+ },
+ {
+ label: "Expires",
+ value: "Aug 14, 2026"
+ },
+ {
+ label: "Status",
+ value: "Requested"
+ }
+ ]}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/QuoteEmail.tsx b/packages/documents/src/email/previews/QuoteEmail.tsx
new file mode 100644
index 0000000000..cf5e60a9d6
--- /dev/null
+++ b/packages/documents/src/email/previews/QuoteEmail.tsx
@@ -0,0 +1,55 @@
+import type { Database } from "@carbon/database";
+import type { CompanySettings } from "../../types";
+import QuoteEmail from "../QuoteEmail";
+
+const company = {
+ name: "Tombstone Machine Works",
+ logoLightIcon: null,
+ baseCurrencyCode: "USD"
+} as unknown as Database["public"]["Views"]["companies"]["Row"];
+
+const quote = {
+ quoteId: "QUO-00042",
+ customerReference: "RFQ-77812",
+ expirationDate: "2026-08-23",
+ externalLinkId: "a1b2c3d4e5f6",
+ externalNotes: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [
+ {
+ type: "text",
+ text: "Pricing includes first article inspection. Lead time is 3 weeks after order confirmation."
+ }
+ ]
+ }
+ ]
+ }
+} as unknown as Database["public"]["Tables"]["quote"]["Row"];
+
+const companySettings = {
+ digitalQuoteEnabled: true
+} as unknown as CompanySettings;
+
+export default function QuoteEmailPreview() {
+ return (
+ <QuoteEmail
+ company={company}
+ companySettings={companySettings}
+ locale="en-US"
+ quote={quote}
+ recipient={{
+ firstName: "Tom",
+ lastName: "Sawyer",
+ }}
+ sender={{
+ firstName: "Jane",
+ lastName: "Doe",
+ }}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/SalesInvoiceEmail.tsx b/packages/documents/src/email/previews/SalesInvoiceEmail.tsx
new file mode 100644
index 0000000000..d5dda57fd2
--- /dev/null
+++ b/packages/documents/src/email/previews/SalesInvoiceEmail.tsx
@@ -0,0 +1,107 @@
+import type { Database } from "@carbon/database";
+import SalesInvoiceEmail from "../SalesInvoiceEmail";
+
+const company = {
+ name: "Tombstone Machine Works",
+ logoLightIcon: null,
+ baseCurrencyCode: "USD"
+} as unknown as Database["public"]["Views"]["companies"]["Row"];
+
+const salesInvoice = {
+ invoiceId: "INV-00087",
+ paymentTermId: "payment-term-net-30",
+ dateDue: "2026-08-23",
+ currencyCode: "USD",
+ exchangeRate: 1,
+ externalNotes: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [
+ {
+ type: "text",
+ text: "Please remit payment to the account listed on the attached invoice and reference INV-00087."
+ }
+ ]
+ }
+ ]
+ }
+} as unknown as Database["public"]["Views"]["salesInvoices"]["Row"];
+
+const salesInvoiceLines = [
+ {
+ id: "invoice-line-1",
+ invoiceLineType: "Part",
+ itemReadableId: "BRKT-6061",
+ description: "6061-T6 Aluminum Bracket",
+ quantity: 25,
+ convertedUnitPrice: 68,
+ convertedAddOnCost: 0,
+ convertedNonTaxableAddOnCost: 0,
+ convertedShippingCost: 0,
+ taxPercent: 0.075
+ },
+ {
+ id: "invoice-line-2",
+ invoiceLineType: "Part",
+ itemReadableId: "FAS-M8-125",
+ description: "M8x1.25 Hex Bolt",
+ quantity: 500,
+ convertedUnitPrice: 0.32,
+ convertedAddOnCost: 0,
+ convertedNonTaxableAddOnCost: 0,
+ convertedShippingCost: 0,
+ taxPercent: 0.075
+ },
+ {
+ id: "invoice-line-3",
+ invoiceLineType: "Comment",
+ itemReadableId: null,
+ description: "Thank you for your business.",
+ quantity: null,
+ convertedUnitPrice: null,
+ convertedAddOnCost: null,
+ convertedNonTaxableAddOnCost: null,
+ convertedShippingCost: null,
+ taxPercent: null
+ }
+] as unknown as Database["public"]["Views"]["salesInvoiceLines"]["Row"][];
+
+const salesInvoiceLocations = {
+ invoiceCustomerName: "Globex Inc.",
+ invoiceAddressLine1: "1200 Industrial Parkway",
+ invoiceAddressLine2: "Suite 400",
+ invoiceCity: "Springfield",
+ invoiceStateProvince: "IL",
+ invoicePostalCode: "62704",
+ invoiceCountryName: "United States"
+} as unknown as Database["public"]["Views"]["salesInvoiceLocations"]["Row"];
+
+const salesInvoiceShipment = {
+ shippingCost: 45
+} as unknown as Database["public"]["Tables"]["salesInvoiceShipment"]["Row"];
+
+export default function SalesInvoiceEmailPreview() {
+ return (
+ <SalesInvoiceEmail
+ company={company}
+ locale="en-US"
+ salesInvoice={salesInvoice}
+ salesInvoiceLines={salesInvoiceLines}
+ salesInvoiceLocations={salesInvoiceLocations}
+ salesInvoiceShipment={salesInvoiceShipment}
+ paymentTerms={[{ id: "payment-term-net-30", name: "Net 30" }]}
+ recipient={{
+ firstName: "Tom",
+ lastName: "Sawyer",
+ }}
+ sender={{
+ firstName: "Jane",
+ lastName: "Doe",
+ }}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/SalesOrderEmail.tsx b/packages/documents/src/email/previews/SalesOrderEmail.tsx
new file mode 100644
index 0000000000..ea36ae4401
--- /dev/null
+++ b/packages/documents/src/email/previews/SalesOrderEmail.tsx
@@ -0,0 +1,111 @@
+import type { Database } from "@carbon/database";
+import SalesOrderEmail from "../SalesOrderEmail";
+
+const company = {
+ name: "Tombstone Machine Works",
+ logoLightIcon: null,
+ baseCurrencyCode: "USD"
+} as unknown as Database["public"]["Views"]["companies"]["Row"];
+
+const salesOrder = {
+ salesOrderId: "SO-00123",
+ paymentTermId: "payment-term-net-30",
+ receiptRequestedDate: "2026-09-01",
+ shippingCost: 85,
+ exchangeRate: 1,
+ externalNotes: {
+ type: "doc",
+ content: [
+ {
+ type: "paragraph",
+ content: [
+ {
+ type: "text",
+ text: "All parts ship with certificates of conformance. Contact us before making any change requests after release."
+ }
+ ]
+ }
+ ]
+ }
+} as unknown as Database["public"]["Views"]["salesOrders"]["Row"];
+
+const salesOrderLines = [
+ {
+ id: "so-line-1",
+ salesOrderLineType: "Part",
+ itemReadableId: "BRKT-6061",
+ description: "6061-T6 Aluminum Bracket",
+ customerPartId: "GLX-88451",
+ customerPartRevision: "C",
+ saleQuantity: 25,
+ unitPrice: 68,
+ convertedUnitPrice: 68,
+ convertedAddOnCost: 0,
+ convertedNonTaxableAddOnCost: 0,
+ convertedShippingCost: 0,
+ taxPercent: 0.075
+ },
+ {
+ id: "so-line-2",
+ salesOrderLineType: "Part",
+ itemReadableId: "FAS-M8-125",
+ description: "M8x1.25 Hex Bolt",
+ customerPartId: null,
+ customerPartRevision: null,
+ saleQuantity: 500,
+ unitPrice: 0.32,
+ convertedUnitPrice: 0.32,
+ convertedAddOnCost: 0,
+ convertedNonTaxableAddOnCost: 0,
+ convertedShippingCost: 0,
+ taxPercent: 0.075
+ },
+ {
+ id: "so-line-3",
+ salesOrderLineType: "Comment",
+ itemReadableId: null,
+ description: "Expedite fees waived per agreement with Globex purchasing.",
+ customerPartId: null,
+ customerPartRevision: null,
+ saleQuantity: null,
+ unitPrice: null,
+ convertedUnitPrice: null,
+ convertedAddOnCost: null,
+ convertedNonTaxableAddOnCost: null,
+ convertedShippingCost: null,
+ taxPercent: null
+ }
+] as unknown as Database["public"]["Views"]["salesOrderLines"]["Row"][];
+
+const salesOrderLocations = {
+ customerName: "Globex Inc.",
+ customerAddressLine1: "1200 Industrial Parkway",
+ customerAddressLine2: "Receiving Dock 3",
+ customerCity: "Springfield",
+ customerStateProvince: "IL",
+ customerPostalCode: "62704",
+ customerCountryName: "United States"
+} as unknown as Database["public"]["Views"]["salesOrderLocations"]["Row"];
+
+export default function SalesOrderEmailPreview() {
+ return (
+ <SalesOrderEmail
+ company={company}
+ locale="en-US"
+ salesOrder={salesOrder}
+ salesOrderLines={salesOrderLines}
+ salesOrderLocations={salesOrderLocations}
+ paymentTerms={[{ id: "payment-term-net-30", name: "Net 30" }]}
+ recipient={{
+ firstName: "Tom",
+ lastName: "Sawyer",
+ }}
+ sender={{
+ firstName: "Jane",
+ lastName: "Doe",
+ }}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/VerificationEmail.tsx b/packages/documents/src/email/previews/VerificationEmail.tsx
new file mode 100644
index 0000000000..fa75ad7e9b
--- /dev/null
+++ b/packages/documents/src/email/previews/VerificationEmail.tsx
@@ -0,0 +1,10 @@
+import VerificationEmail from "../VerificationEmail";
+
+export default function VerificationEmailPreview() {
+ return (
+ <VerificationEmail
+ email={"[email protected]"}
+ verificationCode={"482913"}
+ />
+ );
+}
diff --git a/packages/documents/src/email/previews/WelcomeEmail.tsx b/packages/documents/src/email/previews/WelcomeEmail.tsx
new file mode 100644
index 0000000000..819e11bb60
--- /dev/null
+++ b/packages/documents/src/email/previews/WelcomeEmail.tsx
@@ -0,0 +1,5 @@
+import WelcomeEmail from "../WelcomeEmail";
+
+export default function WelcomeEmailPreview() {
+ return <WelcomeEmail />;
+}