Email for professionals and teams
update backup
Hieu Nguyen (Jack)027df5013885
diff --git a/AGENTS.md b/AGENTS.mdnew file mode 100644index 0000000..c71f945--- /dev/null+++ b/AGENTS.md@@ -0,0 +1,7 @@+# Repository agent instructions++## Database backup and restore++- Whenever a migration creates, renames, or removes a persisted table, update the backup and restore table lists in the same change, even if the feature is unrelated to backups. Review `BACKUP_TABLES` and `INTERNAL_TABLES` in `src/lib/backups/export.ts`, `BACKUP_TABLE_GROUPS` in `src/lib/backups/table-groups.ts`, and `DatabaseBackupTable` in `src/lib/backups/types.d.ts`.+- Put every backed-up table in exactly one group. Keep `BACKUP_TABLES` in foreign-key dependency order so restore inserts parents before children and deletes them in reverse order. Exclude a table only when its contents are derived or internally managed, and document why.+- When adding a table, check backup and restore behavior both before and after its migration is applied. Keep older full backup documents restorable.diff --git a/src/app/(admin)/admin/page.tsx b/src/app/(admin)/admin/page.tsxindex acb3c73..594f752 100644--- a/src/app/(admin)/admin/page.tsx+++ b/src/app/(admin)/admin/page.tsx@@ -1,5 +1,5 @@import Link from "next/link";-import { BadgeDollarSign, Bot, Globe2, KeyRound, Mail, Palette, Settings, Users, Webhook } from "lucide-react";+import { BadgeDollarSign, Bot, Globe2, KeyRound, Mail, Palette, Users } from "lucide-react";import { AdminUpdateCard } from "@/components/admin-update-card";import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";diff --git a/src/app/(admin)/backups/page.tsx b/src/app/(admin)/backups/page.tsxindex cd6aea7..117d9e3 100644--- a/src/app/(admin)/backups/page.tsx+++ b/src/app/(admin)/backups/page.tsx@@ -2,13 +2,16 @@import { useEffect, useRef, useState } from "react";import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";+import * as DropdownMenu from "@radix-ui/react-dropdown-menu";import {AlertTriangle,DatabaseBackup,Download,+ MoreVertical,Play,RefreshCw,Save,+ Settings,Trash2,Upload,} from "lucide-react";@@ -21,6 +24,7 @@ import {CardHeader,CardTitle,} from "@/components/ui/card";+import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";import { Input } from "@/components/ui/input";import { Label } from "@/components/ui/label";import { Select } from "@/components/ui/select";@@ -44,7 +48,9 @@ import {export default function BackupsPage() {const queryClient = useQueryClient();const restoreInput = useRef<HTMLInputElement | null>(null);+ const savedSettings = useRef<BackupSettings | null>(null);const [settings, setSettings] = useState<BackupSettings | null>(null);+ const [settingsOpen, setSettingsOpen] = useState(false);const backups = useQuery({queryKey: ["backups"],queryFn: fetchBackups,@@ -57,15 +63,26 @@ export default function BackupsPage() {});useEffect(() => {- if (backups.data?.settings) setSettings(backups.data.settings);- }, [backups.data?.settings]);+ if (backups.data?.settings && !settings) {+ savedSettings.current = backups.data.settings;+ setSettings(backups.data.settings);+ }+ }, [backups.data?.settings, settings]);const saveSettings = useMutation({- mutationFn: async () => {- if (!settings) return;- await saveBackupSettings(settings);+ mutationFn: saveBackupSettings,+ onSuccess: (_data, nextSettings) => {+ savedSettings.current = nextSettings;+ setSettingsOpen(false);+ return queryClient.invalidateQueries({ queryKey: ["backups"] });},- onSuccess: () => queryClient.invalidateQueries({ queryKey: ["backups"] }),+ });++ const autoSaveSettings = useMutation({+ mutationFn: saveBackupSettings,+ onMutate: (nextSettings) => setSettings(nextSettings),+ onSuccess: (_data, nextSettings) => { savedSettings.current = nextSettings; },+ onError: () => { if (savedSettings.current) setSettings(savedSettings.current); },});const runBackup = useMutation({@@ -86,6 +103,7 @@ export default function BackupsPage() {const error =backups.error ||saveSettings.error ||+ autoSaveSettings.error ||runBackup.error ||deleteBackup.error ||download.error ||@@ -101,7 +119,7 @@ export default function BackupsPage() {Database Backups</h1><p className="mt-1 text-sm text-neutral-500">- Export database records through the D1 binding and store them in the configured R2 bucket.+ Export database records and store them in the configured R2 bucket.</p></div><div className="flex items-center gap-2">@@ -117,17 +135,55 @@ export default function BackupsPage() {restore.mutate(file);}}/>- <Button type="button" variant="outline" disabled={restore.isPending} onClick={() => restoreInput.current?.click()}>- <Upload className="h-4 w-4" />- {restore.isPending ? "Restoring..." : "Restore"}- </Button><Button onClick={() => runBackup.mutate()} disabled={runBackup.isPending || !backupConfigured}>- <Play className="h-4 w-4" />- {runBackup.isPending ? "Starting..." : "Back up now"}+ <Play size={18} />+ {runBackup.isPending ? "Starting..." : "Back up"}</Button>+ <DropdownMenu.Root>+ <DropdownMenu.Trigger asChild>+ <Button type="button" variant="outline" className="h-10 w-10 px-0" aria-label="Backup actions">+ <MoreVertical className="h-4 w-4" />+ </Button>+ </DropdownMenu.Trigger>+ <DropdownMenu.Portal>+ <DropdownMenu.Content align="end" sideOffset={6} className="z-50 min-w-48 rounded-lg border border-neutral-200 bg-white p-1 text-sm shadow-lg">+ <DropdownMenu.Item disabled={restore.isPending} onSelect={() => restoreInput.current?.click()} className="flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-neutral-900 outline-none hover:bg-neutral-100 focus:bg-neutral-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50">+ <Upload className="h-4 w-4" />+ {restore.isPending ? "Restoring..." : "Restore from backup"}+ </DropdownMenu.Item>+ <DropdownMenu.Item disabled={!settings || autoSaveSettings.isPending} onSelect={() => setSettingsOpen(true)} className="flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-neutral-900 outline-none hover:bg-neutral-100 focus:bg-neutral-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50">+ <Settings className="h-4 w-4" />+ Settings+ </DropdownMenu.Item>+ </DropdownMenu.Content>+ </DropdownMenu.Portal>+ </DropdownMenu.Root></div></div>+ <Dialog open={settingsOpen} onOpenChange={setSettingsOpen}>+ <DialogContent className="max-h-[calc(100vh-4rem)] overflow-y-auto">+ <DialogHeader>+ <DialogTitle>Tables to back up</DialogTitle>+ <DialogDescription>Choose related groups of tables for manual and automatic backups. All groups are enabled by default. Restore requires a backup containing every group.</DialogDescription>+ </DialogHeader>+ {settings && <div className="space-y-5">+ <div className="divide-y divide-neutral-100">+ {BACKUP_TABLE_GROUPS.map((group) => {+ const enabled = !settings.excludedTableGroups.includes(group.id);+ const lastEnabled = enabled && settings.excludedTableGroups.length === BACKUP_TABLE_GROUPS.length - 1;+ return <div key={group.id} className="flex items-start justify-between gap-4 py-4 first:pt-0 last:pb-0">+ <div className="min-w-0"><p className="text-sm font-medium text-neutral-900">{group.label}</p><p className="mt-1 break-words text-xs text-neutral-500">Tables: {group.tables.join(", ")}</p></div>+ <Switch checked={enabled} disabled={lastEnabled} onCheckedChange={(checked) => setSettings({ ...settings, excludedTableGroups: checked ? settings.excludedTableGroups.filter((id) => id !== group.id) : [...settings.excludedTableGroups, group.id] })} aria-label={`Back up ${group.label}`} />+ </div>;+ })}+ </div>+ {saveSettings.error && <p className="text-sm text-red-700">{saveSettings.error instanceof Error ? saveSettings.error.message : "Failed to save backup settings"}</p>}+ <Button onClick={() => saveSettings.mutate(settings)} disabled={saveSettings.isPending}><Save className="h-4 w-4" />{saveSettings.isPending ? "Saving..." : "Save settings"}</Button>+ </div>}+ </DialogContent>+ </Dialog>+{error && (<p className="rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">{error instanceof Error ? error.message : "Backup operation failed"}@@ -191,29 +247,29 @@ export default function BackupsPage() {<CardContent className="space-y-5 pt-5">{settings && (<>- <div className="flex items-center gap-3 text-sm font-medium">+ <div className="flex items-center justify-between gap-4 border-t border-neutral-100 pt-5">+ <Label htmlFor="automatic-backup-switch">Enable Automatic backup</Label><Switch+ id="automatic-backup-switch"checked={settings.enabled}- onCheckedChange={(enabled) =>- setSettings({ ...settings, enabled })- }- aria-label="Enable automatic backups"+ disabled={autoSaveSettings.isPending}+ onCheckedChange={(enabled) => autoSaveSettings.mutate({ ...settings, enabled })}/>- <span>Enable automatic backups</span></div>-{settings.enabled && (<><div className="grid gap-4">- <div className="space-y-2">- <Label htmlFor="schedule-type">Frequency</Label>+ <div className="flex items-center justify-between gap-4">+ <Label htmlFor="schedule-type" className="flex-1">Frequency</Label><Selectid="schedule-type"value={settings.scheduleType}+ containerClassName="w-1/2 max-w-52 shrink-0 text-sm"+ disabled={autoSaveSettings.isPending}onChange={(event) => {const scheduleType = event.target.value as BackupSettings["scheduleType"];- setSettings({+ autoSaveSettings.mutate({...settings,scheduleType,scheduleValue:@@ -224,7 +280,8 @@ export default function BackupsPage() {: null,});}}- className="flex h-10 w-full rounded-md border border-neutral-200 bg-white px-3 text-sm"+ // className="flex h-10 w-full rounded-md border border-neutral-200 bg-white px-3 text-sm"+ className="px-3 py-2"><option value="daily">Daily</option><option value="weekly">Selected day of week</option>@@ -233,13 +290,15 @@ export default function BackupsPage() {</div>{settings.scheduleType === "weekly" && (- <div className="space-y-2">+ <div className="flex items-center justify-between gap-4"><Label htmlFor="weekday">Day of week</Label><Selectid="weekday"value={settings.scheduleValue ?? 1}+ containerClassName="w-1/2 max-w-52 shrink-0"+ disabled={autoSaveSettings.isPending}onChange={(event) =>- setSettings({+ autoSaveSettings.mutate({...settings,scheduleValue: Number(event.target.value),})@@ -256,93 +315,82 @@ export default function BackupsPage() {)}{settings.scheduleType === "monthly" && (- <div className="space-y-2">+ <div className="flex items-center justify-between gap-4"><Label htmlFor="month-day">Day of month</Label><Inputid="month-day"+ className="w-1/2 max-w-52 shrink-0"type="number"min={1}max={28}value={settings.scheduleValue ?? 1}+ disabled={autoSaveSettings.isPending}onChange={(event) =>setSettings({...settings,scheduleValue: Number(event.target.value),})}+ onBlur={(event) => {+ if (event.currentTarget.checkValidity()) autoSaveSettings.mutate(settings);+ else setSettings({ ...settings, scheduleValue: savedSettings.current?.scheduleValue ?? 1 });+ }}/></div>)}</div><div className="grid gap-4 border-t border-neutral-100 pt-5">- <div className="flex items-center gap-3 text-sm font-medium">+ <div className="flex items-center justify-between gap-4">+ <Label htmlFor="retention-switch">Delete old backups automatically</Label><Switch+ id="retention-switch"checked={settings.retentionEnabled}+ disabled={autoSaveSettings.isPending}onCheckedChange={(retentionEnabled) =>- setSettings({+ autoSaveSettings.mutate({...settings,retentionEnabled,})}- aria-label="Delete old backups automatically"/>- <span>Delete old backups automatically</span></div>- <div className="space-y-2">+ <div className="flex items-center justify-between gap-4"><Label htmlFor="retention-days">Delete backups older than</Label>- <div className="flex items-center gap-2">+ <div className="flex w-1/2 max-w-52 shrink-0 items-center gap-2 relative"><Inputid="retention-days"+ className="min-w-0"type="number"min={1}max={3650}value={settings.retentionDays}- disabled={!settings.retentionEnabled}+ disabled={!settings.retentionEnabled || autoSaveSettings.isPending}onChange={(event) =>setSettings({...settings,retentionDays: Number(event.target.value),})}+ onBlur={(event) => {+ if (event.currentTarget.checkValidity()) autoSaveSettings.mutate(settings);+ else setSettings({ ...settings, retentionDays: savedSettings.current?.retentionDays ?? 30 });+ }}/>- <span className="text-sm text-neutral-500">days</span>+ <span className="text-sm text-neutral-500 absolute z-10 right-6">days</span></div></div></div></>)}-</>)}</CardContent></Card>- <Card className="rounded-3xl border-0 bg-white p-6">- <CardHeader className="py-0">- <CardTitle>Tables to back up</CardTitle>- <CardDescription>Choose related groups of tables for manual and automatic backups. All groups are enabled by default. Restore requires a backup containing every group.</CardDescription>- </CardHeader>- <CardContent className="space-y-5 pt-5">- {settings && <>- <div className="divide-y divide-neutral-100">- {BACKUP_TABLE_GROUPS.map((group) => {- const enabled = !settings.excludedTableGroups.includes(group.id);- const lastEnabled = enabled && settings.excludedTableGroups.length === BACKUP_TABLE_GROUPS.length - 1;- return <div key={group.id} className="flex items-start justify-between gap-4 py-4 first:pt-0 last:pb-0">- <div className="min-w-0"><p className="text-sm font-medium text-neutral-900">{group.label}</p><p className="mt-1 break-words text-xs text-neutral-500">Tables: {group.tables.join(", ")}</p></div>- <Switch checked={enabled} disabled={lastEnabled} onCheckedChange={(checked) => setSettings({ ...settings, excludedTableGroups: checked ? settings.excludedTableGroups.filter((id) => id !== group.id) : [...settings.excludedTableGroups, group.id] })} aria-label={`Back up ${group.label}`} />- </div>;- })}- </div>- <Button onClick={() => saveSettings.mutate()} disabled={saveSettings.isPending}><Save className="h-4 w-4" />{saveSettings.isPending ? "Saving..." : "Save settings"}</Button>- </>}- </CardContent>- </Card>-<section className="overflow-hidden rounded-3xl bg-white"><div className="flex items-center gap-3 border-b border-neutral-100 px-4 py-4"><DatabaseBackup className="h-5 w-5 text-neutral-500" />diff --git a/src/app/(dashboard)/inbox/[messageId]/page.tsx b/src/app/(dashboard)/inbox/[messageId]/page.tsxindex 48d5899..29a13fb 100644--- a/src/app/(dashboard)/inbox/[messageId]/page.tsx+++ b/src/app/(dashboard)/inbox/[messageId]/page.tsx@@ -181,7 +181,7 @@ export default function MessageDetailPage() {<h1 className={clsx(!isAnyPanelVisible ? "pl-16" : "pl-10", "pr-6 pb-2 pt-4 text-2xl font-medium text-neutral-900")} title={message.subject ?? "(no subject)"}>{message.subject ?? "(no subject)"}</h1>- <div className="px-6">+ {/* <div className="px-6"><div className="mx-auto w-full max-w-[640px]"><SpamScoreDetailsscore={message.spamScore}@@ -190,7 +190,7 @@ export default function MessageDetailPage() {analysisError={message.spamAnalysisError}/></div>- </div>+ </div> */}<ConversationThreadcurrentMessageId={message.id}position={latestMessagesFirst ? "after" : "before"}diff --git a/src/components/admin-nav.tsx b/src/components/admin-nav.tsxindex 0f33075..8de3311 100644--- a/src/components/admin-nav.tsx+++ b/src/components/admin-nav.tsx@@ -38,12 +38,12 @@ const sections = [{label: "Administration",links: [+ { href: "/api-keys", label: "API keys", icon: KeyRound },{ href: "/general", label: "General", icon: Settings },{ href: "/agent", label: "Agent", icon: Bot },{ href: "/accounts", label: "Accounts", icon: Users },{ href: "/activity", label: "Activity", icon: Activity },{ href: "/backups", label: "Backups", icon: DatabaseBackup },- { href: "/api-keys", label: "API keys", icon: KeyRound },],},{diff --git a/src/lib/backups/export.ts b/src/lib/backups/export.tsindex 7d2d042..9e832fa 100644--- a/src/lib/backups/export.ts+++ b/src/lib/backups/export.ts@@ -2,7 +2,7 @@ import type { BackupTableGroupId, DatabaseBackupDocument, DatabaseBackupTable, Dimport { mergeLegacyMessageBodies } from "./utils";import { BACKUP_TABLE_GROUPS, getSelectedBackupTables } from "./table-groups";-const BACKUP_TABLES: DatabaseBackupTable[] = ["users", "domains", "mailboxes", "mailbox_access", "contacts", "folders", "api_keys", "messages", "message_attachments", "outbound_jobs", "routing_rules", "webhooks", "webhook_deliveries", "sessions", "audit_logs", "backup_settings", "backups", "app_settings", "license_settings", "email_templates", "calendar_events", "auto_reply_deliveries", "spam_token_stats", "spam_reputation", "spam_feedback", "mailbox_aliases", "password_reset_tokens", "mfa_recovery_codes", "login_challenges", "mailbox_agent_settings", "agent_conversations", "agent_chat_messages", "agent_jobs", "agent_draft_metadata", "agent_send_approvals", "mcp_key_mailboxes", 'ai_usage'];+const BACKUP_TABLES: DatabaseBackupTable[] = ["users", "domains", "mailboxes", "mailbox_access", "contacts", "folders", "api_keys", "messages", "message_attachments", "shared_attachment_links", "outbound_jobs", "routing_rules", "webhooks", "webhook_deliveries", "sessions", "audit_logs", "backup_settings", "backups", "app_settings", "license_settings", "email_templates", "calendar_events", "auto_reply_deliveries", "spam_token_stats", "spam_reputation", "spam_feedback", "mailbox_aliases", "password_reset_tokens", "mfa_recovery_codes", "login_challenges", "mailbox_agent_settings", "agent_conversations", "agent_chat_messages", "agent_jobs", "agent_draft_metadata", "agent_send_approvals", "mcp_key_mailboxes", 'ai_usage'];/*** Tables every backup document must contain. Tables added to BACKUP_TABLES* after the format shipped are absent from older documents, so they stay@@ -37,7 +37,7 @@ const INTERNAL_TABLES = [* list. Without this, a migration that adds a table silently produces backups* that omit it, and the omission only surfaces during a restore.*/-export async function assertBackupTablesCoverDatabase(db: D1Database): Promise<void> {+export async function assertBackupTablesCoverDatabase(db: D1Database): Promise<Set<string>> {const conditions = [...INTERNAL_TABLE_PATTERNS.map((pattern) => `name NOT LIKE '${pattern}'`),...INTERNAL_TABLES.map((name) => `name <> '${name}'`),@@ -52,15 +52,20 @@ export async function assertBackupTablesCoverDatabase(db: D1Database): Promise<vconst ungrouped = BACKUP_TABLES.filter((table) => assigned.filter((item) => item === table).length !== 1);const unknown = assigned.filter((table) => !covered.has(table));if (ungrouped.length || unknown.length) throw new Error(`Backup aborted: table groups are out of sync (${[...ungrouped, ...unknown].join(", ")}). Update src/lib/backups/table-groups.ts.`);+ return new Set(result.results.map((row) => row.name));}export async function exportDatabaseRecords(db: D1Database, excludedGroups: BackupTableGroupId[] = []): Promise<Uint8Array> {- await assertBackupTablesCoverDatabase(db);+ const databaseTables = await assertBackupTablesCoverDatabase(db);const selected = getSelectedBackupTables(excludedGroups);const includedTables = BACKUP_TABLES.filter((table) => selected.has(table));if (!includedTables.length) throw new Error("Select at least one backup table group");const tables: DatabaseBackupDocument["tables"] = {};for (const table of includedTables) {+ if (table === "shared_attachment_links" && !databaseTables.has(table)) {+ tables[table] = [];+ continue;+ }const result = await db.prepare(`SELECT * FROM ${table}`).all<DatabaseRecord>();tables[table] = result.results;}@@ -70,12 +75,15 @@ export async function exportDatabaseRecords(db: D1Database, excludedGroups: Backexport async function restoreDatabaseRecords(db: D1Database, content: ArrayBuffer): Promise<void> {const document = parseDatabaseBackup(content);- if (document.includedTables && document.includedTables.length !== BACKUP_TABLES.length) throw new Error("This backup contains selected table groups only. Restore requires a backup that includes every table group.");+ if (document.includedTables && !BACKUP_TABLE_GROUPS.every((group) => group.tables.some((table) => document.includedTables?.includes(table)))) throw new Error("This backup contains selected table groups only. Restore requires a backup that includes every table group.");mergeLegacyMessageBodies(document);fillMissingBackupTables(document);validateDatabaseBackup(document);- for (const table of [...BACKUP_TABLES].reverse()) await db.prepare(`DELETE FROM ${table}`).run();- for (const table of BACKUP_TABLES) {+ const sharedLinksTable = await db.prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'shared_attachment_links'").first<{ name: string }>();+ if (!sharedLinksTable && document.tables.shared_attachment_links?.length) throw new Error("Apply pending database migrations before restoring shared attachment links.");+ const restoreTables = sharedLinksTable ? BACKUP_TABLES : BACKUP_TABLES.filter((table) => table !== "shared_attachment_links");+ for (const table of [...restoreTables].reverse()) await db.prepare(`DELETE FROM ${table}`).run();+ for (const table of restoreTables) {const rows = document.tables[table] ?? [];for (let index = 0; index < rows.length; index += INSERT_BATCH_SIZE) {const statements = rows.slice(index, index + INSERT_BATCH_SIZE).map((row) => createInsertStatement(db, table, row));diff --git a/src/lib/backups/table-groups.ts b/src/lib/backups/table-groups.tsindex cbad4d6..cce8a1f 100644--- a/src/lib/backups/table-groups.ts+++ b/src/lib/backups/table-groups.ts@@ -2,7 +2,7 @@ import type { BackupTableGroupId, DatabaseBackupTable } from "./types";export const BACKUP_TABLE_GROUPS: { id: BackupTableGroupId; label: string; tables: DatabaseBackupTable[] }[] = [{ id: "accounts", label: "Accounts and mailboxes", tables: ["users", "domains", "mailboxes", "mailbox_access", "mailbox_aliases", "contacts", "api_keys", "mcp_key_mailboxes", "sessions", "password_reset_tokens", "mfa_recovery_codes", "login_challenges"] },- { id: "mail", label: "Mail and related data", tables: ["folders", "messages", "message_attachments", "outbound_jobs", "email_templates", "calendar_events", "auto_reply_deliveries", "spam_token_stats", "spam_reputation", "spam_feedback"] },+ { id: "mail", label: "Mail and related data", tables: ["folders", "messages", "message_attachments", "shared_attachment_links", "outbound_jobs", "email_templates", "calendar_events", "auto_reply_deliveries", "spam_token_stats", "spam_reputation", "spam_feedback"] },{ id: "automation", label: "Routing and webhooks", tables: ["routing_rules", "webhooks", "webhook_deliveries"] },{ id: "assistant", label: "Assistant and AI usage", tables: ["mailbox_agent_settings", "agent_conversations", "agent_chat_messages", "agent_jobs", "agent_draft_metadata", "agent_send_approvals", "ai_usage"] },{ id: "system", label: "App settings and history", tables: ["audit_logs", "backup_settings", "backups", "app_settings", "license_settings"] },diff --git a/src/lib/backups/types.d.ts b/src/lib/backups/types.d.tsindex cbbe4c5..4d20d1e 100644--- a/src/lib/backups/types.d.ts+++ b/src/lib/backups/types.d.ts@@ -1,6 +1,6 @@export type BackupScheduleType = "daily" | "weekly" | "monthly";export type BackupTableGroupId = "accounts" | "mail" | "automation" | "assistant" | "system";-export type DatabaseBackupTable = "users" | "domains" | "mailboxes" | "mailbox_access" | "contacts" | "folders" | "api_keys" | "messages" | "message_attachments" | "outbound_jobs" | "routing_rules" | "webhooks" | "webhook_deliveries" | "sessions" | "audit_logs" | "backup_settings" | "backups" | "app_settings" | "license_settings" | "email_templates" | "calendar_events" | "auto_reply_deliveries" | "spam_token_stats" | "spam_reputation" | "spam_feedback" | "mailbox_aliases" | "password_reset_tokens" | "mfa_recovery_codes" | "login_challenges" | "mailbox_agent_settings" | "agent_conversations" | "agent_chat_messages" | "agent_jobs" | "agent_draft_metadata" | "agent_send_approvals" | "mcp_key_mailboxes" | 'ai_usage';+export type DatabaseBackupTable = "users" | "domains" | "mailboxes" | "mailbox_access" | "contacts" | "folders" | "api_keys" | "messages" | "message_attachments" | "shared_attachment_links" | "outbound_jobs" | "routing_rules" | "webhooks" | "webhook_deliveries" | "sessions" | "audit_logs" | "backup_settings" | "backups" | "app_settings" | "license_settings" | "email_templates" | "calendar_events" | "auto_reply_deliveries" | "spam_token_stats" | "spam_reputation" | "spam_feedback" | "mailbox_aliases" | "password_reset_tokens" | "mfa_recovery_codes" | "login_challenges" | "mailbox_agent_settings" | "agent_conversations" | "agent_chat_messages" | "agent_jobs" | "agent_draft_metadata" | "agent_send_approvals" | "mcp_key_mailboxes" | 'ai_usage';export type DatabaseRecord = Record<string, string | number | null>;export type DatabaseBackupDocument = { format: "mailflare-database-backup"; version: 1; createdAt: string; includedTables?: DatabaseBackupTable[]; tables: Partial<Record<DatabaseBackupTable, DatabaseRecord[]>>; };