@burdenoff/microfe-integrations 2026.1107.1 → 2026.1107.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/global-types.d.ts +208 -168
- package/dist/generated/global-types.d.ts.map +1 -1
- package/dist/generated/wspace-operations.d.ts +235 -0
- package/dist/generated/wspace-operations.d.ts.map +1 -1
- package/dist/generated/wspace-operations.js +206 -103
- package/dist/generated/wspace-operations.js.map +1 -1
- package/dist/generated/wspace-types.d.ts +8724 -352
- package/dist/generated/wspace-types.d.ts.map +1 -1
- package/dist/generated/wspace-types.js +5 -1
- package/dist/generated/wspace-types.js.map +1 -1
- package/dist/integrations/components/MailMessageBody.d.ts +7 -0
- package/dist/integrations/components/MailMessageBody.d.ts.map +1 -0
- package/dist/integrations/components/MailMessageBody.js +175 -0
- package/dist/integrations/components/MailMessageBody.js.map +1 -0
- package/dist/integrations/hooks/useMailbox.d.ts +65 -4
- package/dist/integrations/hooks/useMailbox.d.ts.map +1 -1
- package/dist/integrations/hooks/useMailbox.js +108 -29
- package/dist/integrations/hooks/useMailbox.js.map +1 -1
- package/dist/integrations/pages/MailboxInbox.d.ts.map +1 -1
- package/dist/integrations/pages/MailboxInbox.js +418 -251
- package/dist/integrations/pages/MailboxInbox.js.map +1 -1
- package/dist/integrations/store/mailboxStore.d.ts +3 -0
- package/dist/integrations/store/mailboxStore.d.ts.map +1 -1
- package/dist/integrations/store/mailboxStore.js +7 -0
- package/dist/integrations/store/mailboxStore.js.map +1 -1
- package/dist/integrations/utils/mailHtml.d.ts +33 -0
- package/dist/integrations/utils/mailHtml.d.ts.map +1 -0
- package/dist/integrations/utils/mailHtml.js +127 -0
- package/dist/integrations/utils/mailHtml.js.map +1 -0
- package/dist/node_modules/dompurify/dist/purify.es.js +894 -0
- package/dist/node_modules/dompurify/dist/purify.es.js.map +1 -0
- package/package.json +5 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MailboxInbox.js","names":[],"sources":["../../../src/integrations/pages/MailboxInbox.tsx"],"sourcesContent":["import { useEffect, useId, useState, type FormEvent } from 'react';\nimport {\n ArrowLeft,\n Inbox,\n Loader2,\n Mail,\n MailOpen,\n Paperclip,\n PenSquare,\n RefreshCw,\n Reply,\n Search,\n Send,\n X,\n} from 'lucide-react';\nimport { Button, IllustratedEmptyState, PagePurpose } from '@burdenoff/fe-libs/ui';\n\nimport { cn } from '../utils/cn';\nimport { joinPath } from '../utils/paths';\nimport { useTr } from '../hooks/useTr';\nimport { useFormatDate } from '../hooks/useFormatDate';\nimport { useIntegrations } from '../providers/IntegrationsProvider';\nimport {\n MailboxFolder,\n splitRecipients,\n useMailboxAccounts,\n useMailboxMessages,\n useMailboxThread,\n useSendMail,\n useSetMailRead,\n} from '../hooks/useMailbox';\nimport type { MailboxAccount, MailboxMessageSummary } from '../hooks/useMailbox';\nimport { useMailboxStore } from '../store/mailboxStore';\n\ninterface Address {\n name?: string | null;\n email: string;\n}\n\nfunction displayAddress(address: Address | null | undefined): string {\n if (!address) return '';\n return address.name ? `${address.name} <${address.email}>` : address.email;\n}\n\nfunction shortAddress(address: Address | null | undefined): string {\n if (!address) return '';\n return address.name || address.email;\n}\n\nconst FOLDERS: Array<{ value: MailboxFolder; key: string; label: string }> = [\n { value: MailboxFolder.Inbox, key: 'inbox', label: 'Inbox' },\n { value: MailboxFolder.Sent, key: 'sent', label: 'Sent' },\n { value: MailboxFolder.All, key: 'all', label: 'All mail' },\n];\n\n/** Compose a new message or a reply. */\nfunction ComposePanel(props: {\n connectionId: string;\n replyTo?: { messageId: string; to: string; subject: string } | null;\n onClose: () => void;\n onSent: () => void;\n}) {\n const { connectionId, replyTo, onClose, onSent } = props;\n const tr = useTr();\n const ids = useId();\n const { send, sending } = useSendMail();\n const [to, setTo] = useState(replyTo?.to ?? '');\n const [cc, setCc] = useState('');\n const [subject, setSubject] = useState(replyTo?.subject ?? '');\n const [body, setBody] = useState('');\n const [error, setError] = useState<string | null>(null);\n\n const handleSubmit = async (event: FormEvent) => {\n event.preventDefault();\n setError(null);\n try {\n await send({\n connectionId,\n to: splitRecipients(to),\n cc: splitRecipients(cc),\n subject,\n bodyText: body,\n replyToMessageId: replyTo?.messageId,\n });\n onSent();\n } catch (err) {\n setError(\n err instanceof Error\n ? err.message\n : tr('integrations.mailbox.compose.failed', 'Could not send')\n );\n }\n };\n\n const inputClass =\n 'w-full px-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary';\n\n return (\n <form\n onSubmit={handleSubmit}\n className=\"rounded-xl border border-border-seam bg-bg-surface p-4 space-y-3\"\n aria-label={\n replyTo\n ? tr('integrations.mailbox.compose.replyTitle', 'Reply')\n : tr('integrations.mailbox.compose.title', 'New message')\n }\n >\n <div className=\"flex items-center justify-between\">\n <h2 className=\"text-sm font-semibold text-text-primary\">\n {replyTo\n ? tr('integrations.mailbox.compose.replyTitle', 'Reply')\n : tr('integrations.mailbox.compose.title', 'New message')}\n </h2>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n onClick={onClose}\n // A pending send must finish before its draft can be dismissed, so it\n // can never close a newer draft when it completes.\n disabled={sending}\n aria-label={tr('integrations.common.close', 'Close')}\n >\n <X size={16} />\n </Button>\n </div>\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-to`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.to', 'To')}\n </label>\n <input\n id={`${ids}-to`}\n type=\"text\"\n value={to}\n onChange={(e) => setTo(e.target.value)}\n placeholder={tr(\n 'integrations.mailbox.compose.toPlaceholder',\n 'name@example.com, another@example.com'\n )}\n className={inputClass}\n required\n />\n </div>\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-cc`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.cc', 'Cc')}\n </label>\n <input\n id={`${ids}-cc`}\n type=\"text\"\n value={cc}\n onChange={(e) => setCc(e.target.value)}\n className={inputClass}\n />\n </div>\n {!replyTo && (\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-subject`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.subject', 'Subject')}\n </label>\n <input\n id={`${ids}-subject`}\n type=\"text\"\n value={subject}\n onChange={(e) => setSubject(e.target.value)}\n maxLength={998}\n className={inputClass}\n />\n </div>\n )}\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-body`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.body', 'Message')}\n </label>\n <textarea\n id={`${ids}-body`}\n value={body}\n onChange={(e) => setBody(e.target.value)}\n rows={8}\n className={cn(inputClass, 'resize-y')}\n required\n />\n </div>\n {error && (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error}\n </p>\n )}\n <div className=\"flex justify-end gap-2\">\n <Button type=\"button\" variant=\"outline\" onClick={onClose} disabled={sending}>\n {tr('integrations.common.cancel', 'Cancel')}\n </Button>\n <Button type=\"submit\" disabled={sending || !body.trim() || !to.trim()}>\n {sending ? <Loader2 size={16} className=\"animate-spin\" /> : <Send size={16} />}\n {tr('integrations.mailbox.compose.send', 'Send')}\n </Button>\n </div>\n </form>\n );\n}\n\n/** One conversation, oldest message first, with a reply box. */\nfunction ThreadView(props: {\n connectionId: string;\n threadId: string;\n /** The connected account's own address, used to pick the reply recipient. */\n accountEmail: string | null;\n onBack: () => void;\n}) {\n const { connectionId, threadId, accountEmail, onBack } = props;\n const tr = useTr();\n const formatDate = useFormatDate();\n const { thread, loading, error, refetch } = useMailboxThread(connectionId, threadId);\n // The parent keys this view by thread id, so reply / notice state starts\n // fresh for every conversation without resetting it in an effect.\n const [replyOpen, setReplyOpen] = useState(false);\n const [sentNotice, setSentNotice] = useState(false);\n\n if (loading && !thread) {\n return (\n <div className=\"flex items-center justify-center py-16\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n </div>\n );\n }\n if (error || !thread) {\n return (\n <div className=\"p-6 space-y-3 text-center\">\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error?.message ?? tr('integrations.mailbox.thread.notFound', 'Conversation not found')}\n </p>\n <div className=\"flex flex-wrap justify-center gap-2\">\n <Button variant=\"ghost\" onClick={onBack}>\n <ArrowLeft size={16} /> {tr('integrations.common.back', 'Back')}\n </Button>\n <Button variant=\"outline\" onClick={() => refetch()}>\n <RefreshCw size={16} /> {tr('integrations.mailbox.actions.retry', 'Try again')}\n </Button>\n </div>\n </div>\n );\n }\n\n const last = thread.messages[thread.messages.length - 1];\n const ownAddress = accountEmail?.trim().toLowerCase() ?? null;\n // Replying to a message the connected account sent itself (from Sent, or a\n // follow-up) goes to that message's recipients, never back to the account.\n const replyRecipients = last\n ? ownAddress && last.from?.email.toLowerCase() === ownAddress\n ? last.to\n .map((address) => address.email)\n .filter((email) => email.toLowerCase() !== ownAddress)\n : [last.from?.email ?? '']\n : [];\n return (\n <div className=\"space-y-4\" data-testid=\"mailbox-thread\">\n <div className=\"flex items-start gap-2\">\n <Button\n variant=\"ghost\"\n size=\"icon\"\n className=\"lg:hidden\"\n onClick={onBack}\n aria-label={tr('integrations.common.back', 'Back')}\n >\n <ArrowLeft size={18} />\n </Button>\n <h2 className=\"text-lg font-semibold text-text-primary break-words\">\n {thread.subject || tr('integrations.mailbox.noSubject', '(no subject)')}\n </h2>\n </div>\n {thread.messages.map((message) => (\n <article\n key={message.id}\n className=\"rounded-xl border border-border-subtle bg-bg-surface p-4 space-y-2\"\n >\n <header className=\"flex flex-wrap items-baseline justify-between gap-2\">\n <div className=\"min-w-0\">\n <p className=\"text-sm font-medium text-text-primary break-all\">\n {displayAddress(message.from)}\n </p>\n <p className=\"text-xs text-text-secondary break-all\">\n {tr('integrations.mailbox.thread.to', 'To')}:{' '}\n {message.to.map(displayAddress).join(', ')}\n {message.cc.length > 0 &&\n ` · ${tr('integrations.mailbox.thread.cc', 'Cc')}: ${message.cc.map(displayAddress).join(', ')}`}\n </p>\n </div>\n <div className=\"flex items-center gap-2 text-xs text-text-tertiary\">\n {message.hasAttachments && (\n <Paperclip\n size={14}\n aria-label={tr('integrations.mailbox.attachments', 'Has attachments')}\n />\n )}\n {message.receivedAt && (\n <time dateTime={message.receivedAt}>{formatDate(message.receivedAt)}</time>\n )}\n </div>\n </header>\n <div className=\"whitespace-pre-wrap break-words text-sm text-text-primary\">\n {message.bodyText}\n </div>\n </article>\n ))}\n {sentNotice && (\n <p role=\"status\" className=\"text-sm text-status-success-text\">\n {tr('integrations.mailbox.compose.sent', 'Message sent')}\n </p>\n )}\n {last &&\n (replyOpen ? (\n <ComposePanel\n connectionId={connectionId}\n replyTo={{\n messageId: last.id,\n to: replyRecipients.filter(Boolean).join(', '),\n subject: thread.subject,\n }}\n onClose={() => setReplyOpen(false)}\n onSent={() => {\n setReplyOpen(false);\n setSentNotice(true);\n void refetch();\n }}\n />\n ) : (\n <Button variant=\"outline\" onClick={() => setReplyOpen(true)}>\n <Reply size={16} /> {tr('integrations.mailbox.actions.reply', 'Reply')}\n </Button>\n ))}\n </div>\n );\n}\n\n/** One page of messages in the selected folder, with paging. */\nfunction MessageList(props: {\n messages: MailboxMessageSummary[];\n loading: boolean;\n error: { message: string } | undefined;\n refetch: () => unknown;\n folder: MailboxFolder;\n threadId: string | null;\n hasPrevious: boolean;\n nextPageToken: string | null;\n onOpen: (threadId: string, messageId: string, unread: boolean) => void;\n onPrevious: () => void;\n onNext: (token: string) => void;\n}) {\n const {\n messages,\n loading,\n error,\n refetch,\n folder,\n threadId,\n hasPrevious,\n nextPageToken,\n onOpen,\n onPrevious,\n onNext,\n } = props;\n const tr = useTr();\n const formatDate = useFormatDate();\n return (\n <>\n {error ? (\n <div className=\"p-6 text-center space-y-3\">\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error.message}\n </p>\n <Button variant=\"outline\" onClick={() => refetch()}>\n <RefreshCw size={16} /> {tr('integrations.mailbox.actions.retry', 'Try again')}\n </Button>\n </div>\n ) : loading && messages.length === 0 ? (\n <div className=\"flex items-center justify-center py-16\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n </div>\n ) : messages.length === 0 ? (\n <p className=\"p-6 text-sm text-text-secondary text-center\">\n {tr('integrations.mailbox.list.empty', 'No messages here')}\n </p>\n ) : (\n <ul className=\"divide-y divide-border-subtle\" data-testid=\"mailbox-message-list\">\n {messages.map((message) => (\n <li key={message.id}>\n <button\n type=\"button\"\n onClick={() => onOpen(message.threadId, message.id, message.isUnread)}\n aria-current={threadId === message.threadId ? 'true' : undefined}\n className={cn(\n 'w-full text-left px-4 py-3 transition-colors hover:bg-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/30',\n threadId === message.threadId && 'bg-accent'\n )}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span\n className={cn(\n 'truncate text-sm',\n message.isUnread ? 'font-semibold text-text-primary' : 'text-text-secondary'\n )}\n >\n {folder === MailboxFolder.Sent\n ? message.to.map(shortAddress).join(', ')\n : shortAddress(message.from)}\n </span>\n <span className=\"flex shrink-0 items-center gap-1 text-xs text-text-tertiary\">\n {message.hasAttachments && <Paperclip size={12} />}\n {message.isUnread ? <Mail size={12} /> : <MailOpen size={12} />}\n {message.receivedAt ? formatDate(message.receivedAt) : ''}\n </span>\n </div>\n <p\n className={cn(\n 'truncate text-sm',\n message.isUnread ? 'font-medium text-text-primary' : 'text-text-primary'\n )}\n >\n {message.subject || tr('integrations.mailbox.noSubject', '(no subject)')}\n </p>\n <p className=\"truncate text-xs text-text-secondary\">{message.snippet}</p>\n </button>\n </li>\n ))}\n </ul>\n )}\n {(hasPrevious || nextPageToken) && (\n <div className=\"flex justify-between gap-2 border-t border-border-subtle p-3\">\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={!hasPrevious || loading}\n onClick={onPrevious}\n >\n {tr('integrations.common.previous', 'Previous')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={!nextPageToken || loading}\n onClick={() => nextPageToken && onNext(nextPageToken)}\n >\n {tr('integrations.common.next', 'Next')}\n </Button>\n </div>\n )}\n </>\n );\n}\n\n/** Shown until a Gmail or Outlook connection exists (or when listing them failed). */\nfunction MailboxEmptyState(props: { errorMessage: string | null }) {\n const tr = useTr();\n const { basePath = '/', navigate } = useIntegrations();\n const connectPath = joinPath(basePath, 'providers');\n return (\n <div className=\"space-y-6 p-6 max-w-5xl mx-auto\">\n <PagePurpose icon={<Mail size={16} />}>\n {tr(\n 'integrations.mailbox.purpose',\n 'Read and send mail from your own Gmail or Outlook account without leaving Workspaces. Only you can open your mailbox; sharing a connection never shares your mail.'\n )}\n </PagePurpose>\n {props.errorMessage ? (\n <p role=\"alert\" className=\"text-sm text-status-error-text text-center\">\n {props.errorMessage}\n </p>\n ) : (\n <IllustratedEmptyState\n illustration=\"empty-data\"\n title={tr('integrations.mailbox.empty.title', 'Connect a mailbox')}\n description={tr(\n 'integrations.mailbox.empty.description',\n 'Connect Google Gmail or Microsoft Outlook from Providers, then come back here to read and send mail.'\n )}\n action={\n <Button onClick={() => navigate?.(connectPath)}>\n <Mail size={16} />{' '}\n {tr('integrations.mailbox.empty.action', 'Connect Gmail or Outlook')}\n </Button>\n }\n />\n )}\n </div>\n );\n}\n\n/** Title, mailbox switcher and the Compose action. */\nfunction MailboxHeader(props: { accounts: MailboxAccount[]; connectionId: string | null }) {\n const { accounts, connectionId } = props;\n const tr = useTr();\n const ids = useId();\n const composing = useMailboxStore((s) => s.composing);\n const selectConnection = useMailboxStore((s) => s.selectConnection);\n const startCompose = useMailboxStore((s) => s.startCompose);\n const account = accounts.find((a) => a.connectionId === connectionId) ?? null;\n return (\n <div className=\"rounded-xl border border-border-seam bg-accent-wash p-4 sm:p-6\">\n <div className=\"flex flex-wrap items-center justify-between gap-4\">\n <div className=\"flex items-center gap-3\">\n <div className=\"p-2.5 rounded-lg bg-action-primary-bg/10\">\n <Inbox size={24} className=\"text-primary\" />\n </div>\n <div>\n <h1 className=\"text-2xl font-bold text-text-primary\">\n {tr('integrations.mailbox.title', 'Inbox')}\n </h1>\n <p className=\"text-sm text-text-secondary\">\n {account?.emailAddress ??\n account?.name ??\n tr('integrations.mailbox.subtitle', 'Your connected mail')}\n </p>\n </div>\n </div>\n <div className=\"flex flex-wrap items-center gap-2\">\n {accounts.length > 1 && (\n <>\n <label htmlFor={`${ids}-account`} className=\"sr-only\">\n {tr('integrations.mailbox.account', 'Mailbox')}\n </label>\n <select\n id={`${ids}-account`}\n value={connectionId ?? ''}\n // An open draft stays bound to the mailbox it was started in.\n disabled={composing}\n onChange={(e) => selectConnection(e.target.value)}\n className=\"px-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary\"\n >\n {accounts.map((a) => (\n <option key={a.connectionId} value={a.connectionId}>\n {a.emailAddress ?? a.name}\n </option>\n ))}\n </select>\n </>\n )}\n <Button onClick={startCompose}>\n <PenSquare size={16} /> {tr('integrations.mailbox.actions.compose', 'Compose')}\n </Button>\n </div>\n </div>\n </div>\n );\n}\n\n/** Folder switcher, search box and refresh. */\nfunction MailboxToolbar(props: { loading: boolean; onRefresh: () => void }) {\n const tr = useTr();\n const folder = useMailboxStore((s) => s.folder);\n const query = useMailboxStore((s) => s.query);\n const selectFolder = useMailboxStore((s) => s.selectFolder);\n const search = useMailboxStore((s) => s.search);\n // The text being typed is a form draft; it becomes the query on submit.\n const [searchInput, setSearchInput] = useState(query);\n return (\n <div className=\"flex flex-col sm:flex-row gap-3\">\n <div\n className=\"flex gap-1 rounded-lg border border-border-subtle bg-bg-surface p-1\"\n role=\"group\"\n aria-label={tr('integrations.mailbox.folders.ariaLabel', 'Folders')}\n >\n {FOLDERS.map((f) => (\n <button\n key={f.value}\n type=\"button\"\n aria-pressed={folder === f.value}\n onClick={() => selectFolder(f.value)}\n className={cn(\n 'px-3 py-1.5 text-sm rounded-md transition-colors',\n folder === f.value\n ? 'bg-action-primary-bg text-action-primary-text'\n : 'text-text-secondary hover:bg-accent'\n )}\n >\n {tr(`integrations.mailbox.folders.${f.key}`, f.label)}\n </button>\n ))}\n </div>\n <form\n className=\"flex-1 relative\"\n onSubmit={(e) => {\n e.preventDefault();\n search(searchInput);\n }}\n >\n <Search\n size={16}\n className=\"absolute left-3 top-1/2 -translate-y-1/2 text-text-secondary\"\n />\n <input\n type=\"search\"\n value={searchInput}\n onChange={(e) => setSearchInput(e.target.value)}\n maxLength={500}\n aria-label={tr('integrations.mailbox.search.ariaLabel', 'Search mail')}\n placeholder={tr('integrations.mailbox.search.placeholder', 'Search mail')}\n className=\"w-full pl-9 pr-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary\"\n />\n </form>\n <Button variant=\"outline\" onClick={props.onRefresh} disabled={props.loading}>\n <RefreshCw size={16} className={cn(props.loading && 'animate-spin')} />{' '}\n {tr('integrations.mailbox.actions.refresh', 'Refresh')}\n </Button>\n </div>\n );\n}\n\n/** Message list and the reading / compose pane for one connected mailbox. */\nfunction MailboxWorkspace(props: { accounts: MailboxAccount[] }) {\n const { accounts } = props;\n const tr = useTr();\n const state = useMailboxStore();\n const resetMailbox = useMailboxStore((s) => s.reset);\n const setRead = useSetMailRead();\n\n // Leaving the Inbox (or switching workspace) starts the next visit clean.\n useEffect(() => resetMailbox, [resetMailbox]);\n\n // Default to the first connected mailbox until the person picks another one;\n // a selection that is no longer connected falls back the same way.\n const account =\n accounts.find((a) => a.connectionId === state.selectedConnectionId) ?? accounts[0] ?? null;\n const connectionId = account?.connectionId ?? null;\n\n const { messages, nextPageToken, loading, error, refetch } = useMailboxMessages({\n connectionId,\n folder: state.folder,\n query: state.query,\n pageToken: state.pageTokens[state.pageTokens.length - 1] ?? null,\n });\n\n const openThread = (id: string, messageId: string, unread: boolean) => {\n state.openThread(id);\n if (unread && connectionId) {\n // Best effort: a failed mark-read must not block reading.\n setRead(connectionId, messageId, true).then(\n () => refetch(),\n () => undefined\n );\n }\n };\n\n const detailOpen = Boolean(state.threadId || state.composing);\n\n return (\n <div className=\"space-y-4 p-4 sm:p-6 max-w-7xl mx-auto\" data-testid=\"mailbox-inbox\">\n <MailboxHeader accounts={accounts} connectionId={connectionId} />\n <MailboxToolbar loading={loading} onRefresh={() => void refetch()} />\n\n {state.sentNotice && (\n <p role=\"status\" className=\"text-sm text-status-success-text\">\n {tr('integrations.mailbox.compose.sent', 'Message sent')}\n </p>\n )}\n\n <div className=\"grid gap-4 lg:grid-cols-[minmax(0,2fr)_minmax(0,3fr)]\">\n <section\n aria-label={tr('integrations.mailbox.list.ariaLabel', 'Messages')}\n className={cn(\n 'rounded-xl border border-border-subtle bg-bg-surface overflow-hidden',\n detailOpen && 'hidden lg:block'\n )}\n >\n <MessageList\n messages={messages}\n loading={loading}\n error={error}\n refetch={refetch}\n folder={state.folder}\n threadId={state.threadId}\n hasPrevious={state.pageTokens.length > 1}\n nextPageToken={nextPageToken}\n onOpen={openThread}\n onPrevious={state.previousPage}\n onNext={state.nextPage}\n />\n </section>\n\n <section className={cn(!detailOpen && 'hidden lg:block')}>\n {state.composing && connectionId ? (\n <ComposePanel\n connectionId={connectionId}\n onClose={state.closeCompose}\n onSent={() => {\n state.composeSent();\n if (state.folder === MailboxFolder.Sent) void refetch();\n }}\n />\n ) : state.threadId && connectionId ? (\n <ThreadView\n key={`${connectionId}:${state.threadId}`}\n connectionId={connectionId}\n threadId={state.threadId}\n accountEmail={account?.emailAddress ?? null}\n onBack={state.closeThread}\n />\n ) : (\n <div className=\"rounded-xl border border-dashed border-border-subtle p-10 text-center text-sm text-text-secondary\">\n {tr('integrations.mailbox.thread.placeholder', 'Select a message to read it')}\n </div>\n )}\n </section>\n </div>\n </div>\n );\n}\n\n/**\n * Inbox — read, search, reply to and send mail from the caller's own Gmail or\n * Outlook account, connected as an integration (BOFF-4422). Workspaces does not\n * host mail; only the connection owner can open a mailbox.\n */\nexport function MailboxInbox() {\n const { accounts, answered, error } = useMailboxAccounts();\n\n // Until the accounts query has actually answered (it waits for the\n // workspace context), an empty list means \"not asked yet\", not \"none\".\n if (!answered && !error) {\n return (\n <div className=\"flex items-center justify-center py-24\" data-testid=\"mailbox-loading\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n </div>\n );\n }\n if (accounts.length === 0) {\n return <MailboxEmptyState errorMessage={error?.message ?? null} />;\n }\n return <MailboxWorkspace accounts={accounts} />;\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,SAAS,EAAe,GAA6C;AAEnE,QADK,IACE,EAAQ,OAAO,GAAG,EAAQ,KAAK,IAAI,EAAQ,MAAM,KAAK,EAAQ,QADhD;;AAIvB,SAAS,EAAa,GAA6C;AAEjE,QADK,IACE,EAAQ,QAAQ,EAAQ,QADV;;AAIvB,IAAM,IAAuE;CAC3E;EAAE,OAAO,EAAc;EAAO,KAAK;EAAS,OAAO;EAAS;CAC5D;EAAE,OAAO,EAAc;EAAM,KAAK;EAAQ,OAAO;EAAQ;CACzD;EAAE,OAAO,EAAc;EAAK,KAAK;EAAO,OAAO;EAAY;CAC5D;AAGD,SAAS,EAAa,GAKnB;CACD,IAAM,EAAE,iBAAc,YAAS,YAAS,cAAW,GAC7C,IAAK,GAAO,EACZ,IAAM,GAAO,EACb,EAAE,SAAM,eAAY,GAAa,EACjC,CAAC,GAAI,KAAS,EAAS,GAAS,MAAM,GAAG,EACzC,CAAC,GAAI,KAAS,EAAS,GAAG,EAC1B,CAAC,GAAS,KAAc,EAAS,GAAS,WAAW,GAAG,EACxD,CAAC,GAAM,KAAW,EAAS,GAAG,EAC9B,CAAC,GAAO,KAAY,EAAwB,KAAK,EAEjD,IAAe,OAAO,MAAqB;AAE/C,EADA,EAAM,gBAAgB,EACtB,EAAS,KAAK;AACd,MAAI;AASF,GARA,MAAM,EAAK;IACT;IACA,IAAI,EAAgB,EAAG;IACvB,IAAI,EAAgB,EAAG;IACvB;IACA,UAAU;IACV,kBAAkB,GAAS;IAC5B,CAAC,EACF,GAAQ;WACD,GAAK;AACZ,KACE,aAAe,QACX,EAAI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UAAU,EAAM;MAChB,cAAc,GAAS,gBAAgB;MACvC,QAAQ,EAAM;MACd,EALK,GAAG,EAAa,GAAG,EAAM,WAK9B,GAEF,kBAAC,OAAD;MAAK,WAAU;gBACZ,EAAG,2CAA2C,8BAA8B;MACzE,CAAA;KAEA,CAAA,CACN;;GACF;;;AASV,SAAgB,IAAe;CAC7B,IAAM,EAAE,aAAU,aAAU,aAAU,GAAoB;AAc1D,QAVI,CAAC,KAAY,CAAC,IAEd,kBAAC,OAAD;EAAK,WAAU;EAAyC,eAAY;YAClE,kBAAC,GAAD,EAAS,WAAU,oCAAqC,CAAA;EACpD,CAAA,GAGN,EAAS,WAAW,IACf,kBAAC,GAAD,EAAmB,cAAc,GAAO,WAAW,MAAQ,CAAA,GAE7D,kBAAC,GAAD,EAA4B,aAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"MailboxInbox.js","names":[],"sources":["../../../src/integrations/pages/MailboxInbox.tsx"],"sourcesContent":["import { useEffect, useId, useRef, useState, type FormEvent } from 'react';\nimport {\n Archive,\n ArrowLeft,\n Inbox,\n Loader2,\n Mail,\n MailOpen,\n Paperclip,\n PenSquare,\n RefreshCw,\n Reply,\n Search,\n Send,\n Trash2,\n X,\n} from 'lucide-react';\nimport { Button, IllustratedEmptyState, PagePurpose } from '@burdenoff/fe-libs/ui';\n\nimport { cn } from '../utils/cn';\nimport { joinPath } from '../utils/paths';\nimport { useTr } from '../hooks/useTr';\nimport { useFormatDate } from '../hooks/useFormatDate';\nimport { useIntegrations } from '../providers/IntegrationsProvider';\nimport {\n MAILBOX_MAX_ATTACHMENTS,\n MAILBOX_SEND_ATTACHMENT_BYTES,\n MailboxFolder,\n MailboxKind,\n MailboxLabelKind,\n splitRecipients,\n useMailboxAccounts,\n useMailboxLabels,\n useMailboxMessages,\n useMailboxThread,\n useMailboxThreadActions,\n useSendMail,\n useSetMailRead,\n useUploadMailAttachment,\n} from '../hooks/useMailbox';\nimport type {\n MailboxAccount,\n MailboxMessageSummary,\n PendingMailAttachment,\n} from '../hooks/useMailbox';\nimport { useMailboxStore } from '../store/mailboxStore';\nimport { ConfirmDialog } from '../components/ConfirmDialog';\nimport { MailMessageBody } from '../components/MailMessageBody';\nimport { formatBytes } from '../utils/mailHtml';\n\ninterface Address {\n name?: string | null;\n email: string;\n}\n\nfunction displayAddress(address: Address | null | undefined): string {\n if (!address) return '';\n return address.name ? `${address.name} <${address.email}>` : address.email;\n}\n\nfunction shortAddress(address: Address | null | undefined): string {\n if (!address) return '';\n return address.name || address.email;\n}\n\nconst FOLDERS: Array<{ value: MailboxFolder; key: string; label: string }> = [\n { value: MailboxFolder.Inbox, key: 'inbox', label: 'Inbox' },\n { value: MailboxFolder.Sent, key: 'sent', label: 'Sent' },\n { value: MailboxFolder.All, key: 'all', label: 'All mail' },\n];\n\n/** Compose a new message or a reply. */\nfunction ComposePanel(props: {\n connectionId: string;\n kind: MailboxKind;\n replyTo?: { messageId: string; to: string; subject: string } | null;\n onClose: () => void;\n onSent: () => void;\n}) {\n const { connectionId, kind, replyTo, onClose, onSent } = props;\n const tr = useTr();\n const ids = useId();\n const { send, sending } = useSendMail();\n const upload = useUploadMailAttachment();\n const fileInput = useRef<HTMLInputElement | null>(null);\n const [attachments, setAttachments] = useState<PendingMailAttachment[]>([]);\n const [uploading, setUploading] = useState(false);\n const capBytes = MAILBOX_SEND_ATTACHMENT_BYTES[kind];\n const capMb = Math.round((capBytes / (1024 * 1024)) * 10) / 10;\n\n const addFiles = async (list: FileList | null) => {\n const picked = Array.from(list ?? []);\n if (fileInput.current) fileInput.current.value = '';\n if (picked.length === 0) return;\n setError(null);\n if (attachments.length + picked.length > MAILBOX_MAX_ATTACHMENTS) {\n setError(\n tr(\n 'integrations.mailbox.compose.tooManyFiles',\n 'A message can have at most {{max}} attachments',\n { max: MAILBOX_MAX_ATTACHMENTS }\n )\n );\n return;\n }\n const total = [...attachments, ...picked].reduce((sum, f) => sum + f.size, 0);\n if (total > capBytes) {\n setError(\n tr(\n 'integrations.mailbox.compose.filesTooLarge',\n 'Attachments on one message can total at most {{max}} MB with this mailbox',\n { max: capMb }\n )\n );\n return;\n }\n setUploading(true);\n try {\n for (const file of picked) {\n const uploaded = await upload(file);\n setAttachments((current) => [...current, uploaded]);\n }\n } catch (err) {\n setError(\n err instanceof Error\n ? err.message\n : tr('integrations.mailbox.compose.uploadFailed', 'Could not upload the file')\n );\n } finally {\n setUploading(false);\n }\n };\n const [to, setTo] = useState(replyTo?.to ?? '');\n const [cc, setCc] = useState('');\n const [subject, setSubject] = useState(replyTo?.subject ?? '');\n const [body, setBody] = useState('');\n const [error, setError] = useState<string | null>(null);\n\n const handleSubmit = async (event: FormEvent) => {\n event.preventDefault();\n setError(null);\n try {\n await send({\n connectionId,\n to: splitRecipients(to),\n cc: splitRecipients(cc),\n subject,\n bodyText: body,\n replyToMessageId: replyTo?.messageId,\n attachmentFileIds: attachments.map((a) => a.fileId),\n });\n onSent();\n } catch (err) {\n setError(\n err instanceof Error\n ? err.message\n : tr('integrations.mailbox.compose.failed', 'Could not send')\n );\n }\n };\n\n const inputClass =\n 'w-full px-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary';\n\n return (\n <form\n onSubmit={handleSubmit}\n className=\"rounded-xl border border-border-seam bg-bg-surface p-4 space-y-3\"\n aria-label={\n replyTo\n ? tr('integrations.mailbox.compose.replyTitle', 'Reply')\n : tr('integrations.mailbox.compose.title', 'New message')\n }\n >\n <div className=\"flex items-center justify-between\">\n <h2 className=\"text-sm font-semibold text-text-primary\">\n {replyTo\n ? tr('integrations.mailbox.compose.replyTitle', 'Reply')\n : tr('integrations.mailbox.compose.title', 'New message')}\n </h2>\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"icon\"\n onClick={onClose}\n // A pending send must finish before its draft can be dismissed, so it\n // can never close a newer draft when it completes.\n disabled={sending}\n aria-label={tr('integrations.common.close', 'Close')}\n >\n <X size={16} />\n </Button>\n </div>\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-to`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.to', 'To')}\n </label>\n <input\n id={`${ids}-to`}\n type=\"text\"\n value={to}\n onChange={(e) => setTo(e.target.value)}\n placeholder={tr(\n 'integrations.mailbox.compose.toPlaceholder',\n 'name@example.com, another@example.com'\n )}\n className={inputClass}\n required\n />\n </div>\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-cc`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.cc', 'Cc')}\n </label>\n <input\n id={`${ids}-cc`}\n type=\"text\"\n value={cc}\n onChange={(e) => setCc(e.target.value)}\n className={inputClass}\n />\n </div>\n {!replyTo && (\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-subject`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.subject', 'Subject')}\n </label>\n <input\n id={`${ids}-subject`}\n type=\"text\"\n value={subject}\n onChange={(e) => setSubject(e.target.value)}\n maxLength={998}\n className={inputClass}\n />\n </div>\n )}\n <div className=\"space-y-1\">\n <label htmlFor={`${ids}-body`} className=\"text-xs font-medium text-text-secondary\">\n {tr('integrations.mailbox.compose.body', 'Message')}\n </label>\n <textarea\n id={`${ids}-body`}\n value={body}\n onChange={(e) => setBody(e.target.value)}\n rows={8}\n className={cn(inputClass, 'resize-y')}\n required\n />\n </div>\n <div className=\"space-y-2\">\n <input\n ref={fileInput}\n id={`${ids}-files`}\n type=\"file\"\n multiple\n aria-label={tr('integrations.mailbox.compose.attach', 'Attach files')}\n tabIndex={-1}\n className=\"sr-only\"\n onChange={(e) => void addFiles(e.target.files)}\n disabled={sending || uploading}\n />\n <Button\n type=\"button\"\n variant=\"outline\"\n size=\"sm\"\n disabled={sending || uploading || attachments.length >= MAILBOX_MAX_ATTACHMENTS}\n onClick={() => fileInput.current?.click()}\n >\n {uploading ? <Loader2 size={14} className=\"animate-spin\" /> : <Paperclip size={14} />}\n {uploading\n ? tr('integrations.mailbox.compose.uploading', 'Uploading…')\n : tr('integrations.mailbox.compose.attach', 'Attach files')}\n </Button>\n <p className=\"text-xs text-text-tertiary\">\n {tr(\n 'integrations.mailbox.compose.attachHint',\n 'Up to {{count}} files, {{max}} MB in total. A copy is kept in your Files.',\n { count: MAILBOX_MAX_ATTACHMENTS, max: capMb }\n )}\n </p>\n {attachments.length > 0 && (\n <ul className=\"flex flex-wrap gap-2\" data-testid=\"mailbox-compose-attachments\">\n {attachments.map((file) => (\n <li\n key={file.fileId}\n className=\"flex items-center gap-1 rounded-full border border-border-subtle px-3 py-1 text-xs text-text-primary\"\n >\n <Paperclip size={12} />\n <span className=\"max-w-48 truncate\">{file.name}</span>\n <span className=\"text-text-tertiary\">{formatBytes(file.size)}</span>\n <button\n type=\"button\"\n className=\"ml-1 rounded-full p-0.5 hover:bg-accent\"\n disabled={sending}\n aria-label={tr('integrations.mailbox.compose.removeFile', 'Remove {{name}}', {\n name: file.name,\n })}\n onClick={() =>\n setAttachments((current) => current.filter((f) => f.fileId !== file.fileId))\n }\n >\n <X size={12} />\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n {error && (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error}\n </p>\n )}\n <div className=\"flex justify-end gap-2\">\n <Button type=\"button\" variant=\"outline\" onClick={onClose} disabled={sending}>\n {tr('integrations.common.cancel', 'Cancel')}\n </Button>\n <Button type=\"submit\" disabled={sending || uploading || !body.trim() || !to.trim()}>\n {sending ? <Loader2 size={16} className=\"animate-spin\" /> : <Send size={16} />}\n {tr('integrations.mailbox.compose.send', 'Send')}\n </Button>\n </div>\n </form>\n );\n}\n\n/** One conversation, oldest message first, with a reply box. */\nfunction ThreadView(props: {\n connectionId: string;\n kind: MailboxKind;\n threadId: string;\n /** The connected account's own address, used to pick the reply recipient. */\n accountEmail: string | null;\n onBack: () => void;\n /** Called after the conversation was archived or moved to the trash. */\n onRemoved: (action: 'archived' | 'trashed') => void;\n}) {\n const { connectionId, kind, threadId, accountEmail, onBack, onRemoved } = props;\n const tr = useTr();\n const formatDate = useFormatDate();\n const { thread, loading, error, refetch } = useMailboxThread(connectionId, threadId);\n const { archiveThread, trashThread, busy } = useMailboxThreadActions();\n const [confirmTrash, setConfirmTrash] = useState(false);\n const [actionError, setActionError] = useState<string | null>(null);\n\n const runAction = async (action: 'archived' | 'trashed') => {\n setActionError(null);\n try {\n if (action === 'archived') await archiveThread(connectionId, threadId);\n else await trashThread(connectionId, threadId);\n setConfirmTrash(false);\n onRemoved(action);\n } catch (err) {\n setConfirmTrash(false);\n setActionError(\n err instanceof Error\n ? err.message\n : tr('integrations.mailbox.actions.failed', 'That did not work. Try again.')\n );\n }\n };\n // The parent keys this view by thread id, so reply / notice state starts\n // fresh for every conversation without resetting it in an effect.\n const [replyOpen, setReplyOpen] = useState(false);\n const [sentNotice, setSentNotice] = useState(false);\n\n if (loading && !thread) {\n return (\n <div className=\"flex items-center justify-center py-16\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n </div>\n );\n }\n if (error || !thread) {\n return (\n <div className=\"p-6 space-y-3 text-center\">\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error?.message ?? tr('integrations.mailbox.thread.notFound', 'Conversation not found')}\n </p>\n <div className=\"flex flex-wrap justify-center gap-2\">\n <Button variant=\"ghost\" onClick={onBack}>\n <ArrowLeft size={16} /> {tr('integrations.common.back', 'Back')}\n </Button>\n <Button variant=\"outline\" onClick={() => refetch()}>\n <RefreshCw size={16} /> {tr('integrations.mailbox.actions.retry', 'Try again')}\n </Button>\n </div>\n </div>\n );\n }\n\n const last = thread.messages[thread.messages.length - 1];\n const ownAddress = accountEmail?.trim().toLowerCase() ?? null;\n // Replying to a message the connected account sent itself (from Sent, or a\n // follow-up) goes to that message's recipients, never back to the account.\n const replyRecipients = last\n ? ownAddress && last.from?.email.toLowerCase() === ownAddress\n ? last.to\n .map((address) => address.email)\n .filter((email) => email.toLowerCase() !== ownAddress)\n : [last.from?.email ?? '']\n : [];\n return (\n <div className=\"space-y-4\" data-testid=\"mailbox-thread\">\n <div className=\"flex items-start gap-2\">\n <Button\n variant=\"ghost\"\n size=\"icon\"\n className=\"lg:hidden\"\n onClick={onBack}\n aria-label={tr('integrations.common.back', 'Back')}\n >\n <ArrowLeft size={18} />\n </Button>\n <h2 className=\"min-w-0 flex-1 text-lg font-semibold text-text-primary break-words\">\n {thread.subject || tr('integrations.mailbox.noSubject', '(no subject)')}\n </h2>\n <div className=\"flex shrink-0 gap-1\">\n <Button\n variant=\"ghost\"\n size=\"icon\"\n disabled={busy}\n onClick={() => void runAction('archived')}\n aria-label={tr('integrations.mailbox.actions.archive', 'Archive')}\n title={tr('integrations.mailbox.actions.archive', 'Archive')}\n >\n <Archive size={18} />\n </Button>\n <Button\n variant=\"ghost\"\n size=\"icon\"\n disabled={busy}\n onClick={() => setConfirmTrash(true)}\n aria-label={tr('integrations.mailbox.actions.trash', 'Delete')}\n title={tr('integrations.mailbox.actions.trash', 'Delete')}\n >\n <Trash2 size={18} />\n </Button>\n </div>\n </div>\n {actionError && (\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {actionError}\n </p>\n )}\n <ConfirmDialog\n open={confirmTrash}\n title={tr('integrations.mailbox.trash.title', 'Delete this conversation?')}\n description={\n kind === MailboxKind.Outlook\n ? tr(\n 'integrations.mailbox.trash.descriptionOutlook',\n 'It moves to Deleted Items in Outlook, where you can restore it.'\n )\n : tr(\n 'integrations.mailbox.trash.descriptionGmail',\n 'It moves to Trash in Gmail, where you can restore it for 30 days.'\n )\n }\n confirmLabel={tr('integrations.mailbox.actions.trash', 'Delete')}\n cancelLabel={tr('integrations.common.cancel', 'Cancel')}\n loading={busy}\n destructive\n onConfirm={() => void runAction('trashed')}\n onCancel={() => setConfirmTrash(false)}\n />\n {thread.messages.map((message) => (\n <article\n key={message.id}\n className=\"rounded-xl border border-border-subtle bg-bg-surface p-4 space-y-2\"\n >\n <header className=\"flex flex-wrap items-baseline justify-between gap-2\">\n <div className=\"min-w-0\">\n <p className=\"text-sm font-medium text-text-primary break-all\">\n {displayAddress(message.from)}\n </p>\n <p className=\"text-xs text-text-secondary break-all\">\n {tr('integrations.mailbox.thread.to', 'To')}:{' '}\n {message.to.map(displayAddress).join(', ')}\n {message.cc.length > 0 &&\n ` · ${tr('integrations.mailbox.thread.cc', 'Cc')}: ${message.cc.map(displayAddress).join(', ')}`}\n </p>\n </div>\n <div className=\"flex items-center gap-2 text-xs text-text-tertiary\">\n {message.hasAttachments && (\n <Paperclip\n size={14}\n aria-label={tr('integrations.mailbox.attachments', 'Has attachments')}\n />\n )}\n {message.receivedAt && (\n <time dateTime={message.receivedAt}>{formatDate(message.receivedAt)}</time>\n )}\n </div>\n </header>\n <MailMessageBody connectionId={connectionId} message={message} />\n </article>\n ))}\n {sentNotice && (\n <p role=\"status\" className=\"text-sm text-status-success-text\">\n {tr('integrations.mailbox.compose.sent', 'Message sent')}\n </p>\n )}\n {last &&\n (replyOpen ? (\n <ComposePanel\n connectionId={connectionId}\n kind={kind}\n replyTo={{\n messageId: last.id,\n to: replyRecipients.filter(Boolean).join(', '),\n subject: thread.subject,\n }}\n onClose={() => setReplyOpen(false)}\n onSent={() => {\n setReplyOpen(false);\n setSentNotice(true);\n void refetch();\n }}\n />\n ) : (\n <Button variant=\"outline\" onClick={() => setReplyOpen(true)}>\n <Reply size={16} /> {tr('integrations.mailbox.actions.reply', 'Reply')}\n </Button>\n ))}\n </div>\n );\n}\n\n/** One page of messages in the selected folder, with paging. */\nfunction MessageList(props: {\n messages: MailboxMessageSummary[];\n loading: boolean;\n error: { message: string } | undefined;\n refetch: () => unknown;\n folder: MailboxFolder;\n threadId: string | null;\n hasPrevious: boolean;\n nextPageToken: string | null;\n onOpen: (threadId: string, messageId: string, unread: boolean) => void;\n onPrevious: () => void;\n onNext: (token: string) => void;\n}) {\n const {\n messages,\n loading,\n error,\n refetch,\n folder,\n threadId,\n hasPrevious,\n nextPageToken,\n onOpen,\n onPrevious,\n onNext,\n } = props;\n const tr = useTr();\n const formatDate = useFormatDate();\n return (\n <>\n {error ? (\n <div className=\"p-6 text-center space-y-3\">\n <p role=\"alert\" className=\"text-sm text-status-error-text\">\n {error.message}\n </p>\n <Button variant=\"outline\" onClick={() => refetch()}>\n <RefreshCw size={16} /> {tr('integrations.mailbox.actions.retry', 'Try again')}\n </Button>\n </div>\n ) : loading && messages.length === 0 ? (\n <div className=\"flex items-center justify-center py-16\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n </div>\n ) : messages.length === 0 ? (\n <p className=\"p-6 text-sm text-text-secondary text-center\">\n {tr('integrations.mailbox.list.empty', 'No messages here')}\n </p>\n ) : (\n <ul className=\"divide-y divide-border-subtle\" data-testid=\"mailbox-message-list\">\n {messages.map((message) => (\n <li key={message.id}>\n <button\n type=\"button\"\n onClick={() => onOpen(message.threadId, message.id, message.isUnread)}\n aria-current={threadId === message.threadId ? 'true' : undefined}\n className={cn(\n 'w-full text-left px-4 py-3 transition-colors hover:bg-accent focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/30',\n threadId === message.threadId && 'bg-accent'\n )}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span\n className={cn(\n 'truncate text-sm',\n message.isUnread ? 'font-semibold text-text-primary' : 'text-text-secondary'\n )}\n >\n {folder === MailboxFolder.Sent\n ? message.to.map(shortAddress).join(', ')\n : shortAddress(message.from)}\n </span>\n <span className=\"flex shrink-0 items-center gap-1 text-xs text-text-tertiary\">\n {message.hasAttachments && <Paperclip size={12} />}\n {message.isUnread ? <Mail size={12} /> : <MailOpen size={12} />}\n {message.receivedAt ? formatDate(message.receivedAt) : ''}\n </span>\n </div>\n <p\n className={cn(\n 'truncate text-sm',\n message.isUnread ? 'font-medium text-text-primary' : 'text-text-primary'\n )}\n >\n {message.subject || tr('integrations.mailbox.noSubject', '(no subject)')}\n </p>\n <p className=\"truncate text-xs text-text-secondary\">{message.snippet}</p>\n </button>\n </li>\n ))}\n </ul>\n )}\n {(hasPrevious || nextPageToken) && (\n <div className=\"flex justify-between gap-2 border-t border-border-subtle p-3\">\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={!hasPrevious || loading}\n onClick={onPrevious}\n >\n {tr('integrations.common.previous', 'Previous')}\n </Button>\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={!nextPageToken || loading}\n onClick={() => nextPageToken && onNext(nextPageToken)}\n >\n {tr('integrations.common.next', 'Next')}\n </Button>\n </div>\n )}\n </>\n );\n}\n\n/** Shown until a Gmail or Outlook connection exists (or when listing them failed). */\nfunction MailboxEmptyState(props: { errorMessage: string | null }) {\n const tr = useTr();\n const { basePath = '/', navigate } = useIntegrations();\n const connectPath = joinPath(basePath, 'providers');\n return (\n <div className=\"space-y-6 p-6 max-w-5xl mx-auto\">\n <PagePurpose icon={<Mail size={16} />}>\n {tr(\n 'integrations.mailbox.purpose',\n 'Read and send mail from your own Gmail or Outlook account without leaving Workspaces. Only you can open your mailbox; sharing a connection never shares your mail.'\n )}\n </PagePurpose>\n {props.errorMessage ? (\n <p role=\"alert\" className=\"text-sm text-status-error-text text-center\">\n {props.errorMessage}\n </p>\n ) : (\n <IllustratedEmptyState\n illustration=\"empty-data\"\n title={tr('integrations.mailbox.empty.title', 'Connect a mailbox')}\n description={tr(\n 'integrations.mailbox.empty.description',\n 'Connect Google Gmail or Microsoft Outlook from Providers, then come back here to read and send mail.'\n )}\n action={\n <Button onClick={() => navigate?.(connectPath)}>\n <Mail size={16} />{' '}\n {tr('integrations.mailbox.empty.action', 'Connect Gmail or Outlook')}\n </Button>\n }\n />\n )}\n </div>\n );\n}\n\n/** Title, mailbox switcher and the Compose action. */\nfunction MailboxHeader(props: { accounts: MailboxAccount[]; connectionId: string | null }) {\n const { accounts, connectionId } = props;\n const tr = useTr();\n const ids = useId();\n const composing = useMailboxStore((s) => s.composing);\n const selectConnection = useMailboxStore((s) => s.selectConnection);\n const startCompose = useMailboxStore((s) => s.startCompose);\n const account = accounts.find((a) => a.connectionId === connectionId) ?? null;\n return (\n <div className=\"rounded-xl border border-border-seam bg-accent-wash p-4 sm:p-6\">\n <div className=\"flex flex-wrap items-center justify-between gap-4\">\n <div className=\"flex items-center gap-3\">\n <div className=\"p-2.5 rounded-lg bg-action-primary-bg/10\">\n <Inbox size={24} className=\"text-primary\" />\n </div>\n <div>\n <h1 className=\"text-2xl font-bold text-text-primary\">\n {tr('integrations.mailbox.title', 'Inbox')}\n </h1>\n <p className=\"text-sm text-text-secondary\">\n {account?.emailAddress ??\n account?.name ??\n tr('integrations.mailbox.subtitle', 'Your connected mail')}\n </p>\n </div>\n </div>\n <div className=\"flex flex-wrap items-center gap-2\">\n {accounts.length > 1 && (\n <>\n <label htmlFor={`${ids}-account`} className=\"sr-only\">\n {tr('integrations.mailbox.account', 'Mailbox')}\n </label>\n <select\n id={`${ids}-account`}\n value={connectionId ?? ''}\n // An open draft stays bound to the mailbox it was started in.\n disabled={composing}\n onChange={(e) => selectConnection(e.target.value)}\n className=\"px-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary\"\n >\n {accounts.map((a) => (\n <option key={a.connectionId} value={a.connectionId}>\n {a.emailAddress ?? a.name}\n </option>\n ))}\n </select>\n </>\n )}\n <Button onClick={startCompose}>\n <PenSquare size={16} /> {tr('integrations.mailbox.actions.compose', 'Compose')}\n </Button>\n </div>\n </div>\n </div>\n );\n}\n\n/** Folder switcher, search box and refresh. */\n/** Gmail labels already covered by the folder buttons. */\nconst FOLDER_BUTTON_LABELS = new Set(['INBOX', 'SENT']);\n\nfunction MailboxToolbar(props: {\n connectionId: string | null;\n loading: boolean;\n onRefresh: () => void;\n}) {\n const tr = useTr();\n const ids = useId();\n const folder = useMailboxStore((s) => s.folder);\n const folderId = useMailboxStore((s) => s.folderId);\n const query = useMailboxStore((s) => s.query);\n const selectFolder = useMailboxStore((s) => s.selectFolder);\n const selectLabel = useMailboxStore((s) => s.selectLabel);\n const search = useMailboxStore((s) => s.search);\n const { labels } = useMailboxLabels(props.connectionId);\n const extraLabels = labels.filter(\n (l) => !(l.kind === MailboxLabelKind.System && FOLDER_BUTTON_LABELS.has(l.id))\n );\n // The text being typed is a form draft; it becomes the query on submit.\n const [searchInput, setSearchInput] = useState(query);\n return (\n <div className=\"flex flex-col sm:flex-row gap-3\">\n <div\n className=\"flex gap-1 rounded-lg border border-border-subtle bg-bg-surface p-1\"\n role=\"group\"\n aria-label={tr('integrations.mailbox.folders.ariaLabel', 'Folders')}\n >\n {FOLDERS.map((f) => (\n <button\n key={f.value}\n type=\"button\"\n aria-pressed={!folderId && folder === f.value}\n onClick={() => selectFolder(f.value)}\n className={cn(\n 'px-3 py-1.5 text-sm rounded-md transition-colors',\n !folderId && folder === f.value\n ? 'bg-action-primary-bg text-action-primary-text'\n : 'text-text-secondary hover:bg-accent'\n )}\n >\n {tr(`integrations.mailbox.folders.${f.key}`, f.label)}\n </button>\n ))}\n </div>\n {extraLabels.length > 0 && (\n <div>\n <label htmlFor={`${ids}-label`} className=\"sr-only\">\n {tr('integrations.mailbox.labels.ariaLabel', 'Labels and folders')}\n </label>\n <select\n id={`${ids}-label`}\n value={folderId ?? ''}\n onChange={(e) => {\n if (e.target.value) selectLabel(e.target.value);\n else selectFolder(folder);\n }}\n className=\"w-full sm:w-48 px-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary\"\n data-testid=\"mailbox-label-select\"\n >\n <option value=\"\">\n {tr('integrations.mailbox.labels.placeholder', 'More folders…')}\n </option>\n {extraLabels.map((label) => (\n <option key={label.id} value={label.id}>\n {label.unreadCount ? `${label.name} (${label.unreadCount})` : label.name}\n </option>\n ))}\n </select>\n </div>\n )}\n <form\n className=\"flex-1 relative\"\n onSubmit={(e) => {\n e.preventDefault();\n search(searchInput);\n }}\n >\n <Search\n size={16}\n className=\"absolute left-3 top-1/2 -translate-y-1/2 text-text-secondary\"\n />\n <input\n type=\"search\"\n value={searchInput}\n onChange={(e) => setSearchInput(e.target.value)}\n maxLength={500}\n aria-label={tr('integrations.mailbox.search.ariaLabel', 'Search mail')}\n placeholder={tr('integrations.mailbox.search.placeholder', 'Search mail')}\n className=\"w-full pl-9 pr-3 py-2 border border-border-subtle rounded-lg bg-bg-surface text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary\"\n />\n </form>\n <Button variant=\"outline\" onClick={props.onRefresh} disabled={props.loading}>\n <RefreshCw size={16} className={cn(props.loading && 'animate-spin')} />{' '}\n {tr('integrations.mailbox.actions.refresh', 'Refresh')}\n </Button>\n </div>\n );\n}\n\n/** Message list and the reading / compose pane for one connected mailbox. */\nfunction MailboxWorkspace(props: { accounts: MailboxAccount[] }) {\n const { accounts } = props;\n const tr = useTr();\n const state = useMailboxStore();\n const resetMailbox = useMailboxStore((s) => s.reset);\n const setRead = useSetMailRead();\n\n // Leaving the Inbox (or switching workspace) starts the next visit clean.\n useEffect(() => resetMailbox, [resetMailbox]);\n\n // Default to the first connected mailbox until the person picks another one;\n // a selection that is no longer connected falls back the same way.\n const account =\n accounts.find((a) => a.connectionId === state.selectedConnectionId) ?? accounts[0] ?? null;\n const connectionId = account?.connectionId ?? null;\n\n const [notice, setNotice] = useState<string | null>(null);\n const { messages, nextPageToken, loading, error, refetch } = useMailboxMessages({\n connectionId,\n folder: state.folder,\n folderId: state.folderId,\n query: state.query,\n pageToken: state.pageTokens[state.pageTokens.length - 1] ?? null,\n });\n\n const openThread = (id: string, messageId: string, unread: boolean) => {\n setNotice(null);\n state.openThread(id);\n if (unread && connectionId) {\n // Best effort: a failed mark-read must not block reading.\n setRead(connectionId, messageId, true).then(\n () => refetch(),\n () => undefined\n );\n }\n };\n\n const detailOpen = Boolean(state.threadId || state.composing);\n\n return (\n <div className=\"space-y-4 p-4 sm:p-6 max-w-7xl mx-auto\" data-testid=\"mailbox-inbox\">\n <MailboxHeader accounts={accounts} connectionId={connectionId} />\n <MailboxToolbar\n key={connectionId ?? 'none'}\n connectionId={connectionId}\n loading={loading}\n onRefresh={() => void refetch()}\n />\n {notice && !state.threadId && (\n <p role=\"status\" className=\"text-sm text-status-success-text\">\n {notice}\n </p>\n )}\n\n {state.sentNotice && (\n <p role=\"status\" className=\"text-sm text-status-success-text\">\n {tr('integrations.mailbox.compose.sent', 'Message sent')}\n </p>\n )}\n\n <div className=\"grid gap-4 lg:grid-cols-[minmax(0,2fr)_minmax(0,3fr)]\">\n <section\n aria-label={tr('integrations.mailbox.list.ariaLabel', 'Messages')}\n className={cn(\n 'rounded-xl border border-border-subtle bg-bg-surface overflow-hidden',\n detailOpen && 'hidden lg:block'\n )}\n >\n <MessageList\n messages={messages}\n loading={loading}\n error={error}\n refetch={refetch}\n folder={state.folder}\n threadId={state.threadId}\n hasPrevious={state.pageTokens.length > 1}\n nextPageToken={nextPageToken}\n onOpen={openThread}\n onPrevious={state.previousPage}\n onNext={state.nextPage}\n />\n </section>\n\n <section className={cn(!detailOpen && 'hidden lg:block')}>\n {state.composing && connectionId ? (\n <ComposePanel\n connectionId={connectionId}\n kind={account?.kind ?? MailboxKind.Gmail}\n onClose={state.closeCompose}\n onSent={() => {\n state.composeSent();\n if (state.folder === MailboxFolder.Sent) void refetch();\n }}\n />\n ) : state.threadId && connectionId ? (\n <ThreadView\n key={`${connectionId}:${state.threadId}`}\n connectionId={connectionId}\n kind={account?.kind ?? MailboxKind.Gmail}\n threadId={state.threadId}\n accountEmail={account?.emailAddress ?? null}\n onBack={state.closeThread}\n onRemoved={(action) => {\n state.closeThread();\n setNotice(\n action === 'archived'\n ? tr('integrations.mailbox.notice.archived', 'Conversation archived')\n : tr('integrations.mailbox.notice.trashed', 'Conversation moved to the trash')\n );\n void refetch();\n }}\n />\n ) : (\n <div className=\"rounded-xl border border-dashed border-border-subtle p-10 text-center text-sm text-text-secondary\">\n {tr('integrations.mailbox.thread.placeholder', 'Select a message to read it')}\n </div>\n )}\n </section>\n </div>\n </div>\n );\n}\n\n/**\n * Inbox — read, search, reply to and send mail from the caller's own Gmail or\n * Outlook account, connected as an integration (BOFF-4422). Workspaces does not\n * host mail; only the connection owner can open a mailbox.\n */\nexport function MailboxInbox() {\n const { accounts, answered, error } = useMailboxAccounts();\n\n // Until the accounts query has actually answered (it waits for the\n // workspace context), an empty list means \"not asked yet\", not \"none\".\n if (!answered && !error) {\n return (\n <div className=\"flex items-center justify-center py-24\" data-testid=\"mailbox-loading\">\n <Loader2 className=\"size-6 animate-spin text-primary\" />\n </div>\n );\n }\n if (accounts.length === 0) {\n return <MailboxEmptyState errorMessage={error?.message ?? null} />;\n }\n return <MailboxWorkspace accounts={accounts} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuDA,SAAS,EAAe,GAA6C;AAEnE,QADK,IACE,EAAQ,OAAO,GAAG,EAAQ,KAAK,IAAI,EAAQ,MAAM,KAAK,EAAQ,QADhD;;AAIvB,SAAS,EAAa,GAA6C;AAEjE,QADK,IACE,EAAQ,QAAQ,EAAQ,QADV;;AAIvB,IAAM,IAAuE;CAC3E;EAAE,OAAO,EAAc;EAAO,KAAK;EAAS,OAAO;EAAS;CAC5D;EAAE,OAAO,EAAc;EAAM,KAAK;EAAQ,OAAO;EAAQ;CACzD;EAAE,OAAO,EAAc;EAAK,KAAK;EAAO,OAAO;EAAY;CAC5D;AAGD,SAAS,EAAa,GAMnB;CACD,IAAM,EAAE,iBAAc,SAAM,YAAS,YAAS,cAAW,GACnD,IAAK,GAAO,EACZ,IAAM,GAAO,EACb,EAAE,SAAM,eAAY,GAAa,EACjC,IAAS,GAAyB,EAClC,IAAY,EAAgC,KAAK,EACjD,CAAC,GAAa,KAAkB,EAAkC,EAAE,CAAC,EACrE,CAAC,GAAW,KAAgB,EAAS,GAAM,EAC3C,IAAW,EAA8B,IACzC,IAAQ,KAAK,MAAO,KAAY,OAAO,QAAS,GAAG,GAAG,IAEtD,IAAW,OAAO,MAA0B;EAChD,IAAM,IAAS,MAAM,KAAK,KAAQ,EAAE,CAAC;AACrC,MAAI,EAAU,YAAS,EAAU,QAAQ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,CAAA;KAEA,CAAA,CACN;;GACF;;;AASV,SAAgB,KAAe;CAC7B,IAAM,EAAE,aAAU,aAAU,aAAU,GAAoB;AAc1D,QAVI,CAAC,KAAY,CAAC,IAEd,kBAAC,OAAD;EAAK,WAAU;EAAyC,eAAY;YAClE,kBAAC,GAAD,EAAS,WAAU,oCAAqC,CAAA;EACpD,CAAA,GAGN,EAAS,WAAW,IACf,kBAAC,GAAD,EAAmB,cAAc,GAAO,WAAW,MAAQ,CAAA,GAE7D,kBAAC,IAAD,EAA4B,aAAY,CAAA"}
|
|
@@ -3,6 +3,8 @@ import { MailboxFolder } from '../../generated/wspace-types';
|
|
|
3
3
|
interface MailboxState {
|
|
4
4
|
selectedConnectionId: string | null;
|
|
5
5
|
folder: MailboxFolder;
|
|
6
|
+
/** A Gmail label or Outlook folder chosen from the label menu; replaces `folder`. */
|
|
7
|
+
folderId: string | null;
|
|
6
8
|
query: string;
|
|
7
9
|
/** Page tokens visited so far; the last entry is the page on screen. */
|
|
8
10
|
pageTokens: Array<string | null>;
|
|
@@ -11,6 +13,7 @@ interface MailboxState {
|
|
|
11
13
|
sentNotice: boolean;
|
|
12
14
|
selectConnection: (connectionId: string) => void;
|
|
13
15
|
selectFolder: (folder: MailboxFolder) => void;
|
|
16
|
+
selectLabel: (folderId: string) => void;
|
|
14
17
|
search: (query: string) => void;
|
|
15
18
|
nextPage: (token: string) => void;
|
|
16
19
|
previousPage: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailboxStore.d.ts","sourceRoot":"","sources":["../../../src/integrations/store/mailboxStore.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,UAAU,YAAY;IACpB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,UAAU,EAAE,KAAK,CAAC,MAAM,GA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AY,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAgBD,eAAO,MAAM,eAAe,2EAoBzB,CAAC"}
|
|
@@ -4,6 +4,7 @@ import { create as t } from "zustand";
|
|
|
4
4
|
var n = {
|
|
5
5
|
selectedConnectionId: null,
|
|
6
6
|
folder: e.Inbox,
|
|
7
|
+
folderId: null,
|
|
7
8
|
query: "",
|
|
8
9
|
pageTokens: [null],
|
|
9
10
|
threadId: null,
|
|
@@ -17,10 +18,16 @@ var n = {
|
|
|
17
18
|
...n,
|
|
18
19
|
selectConnection: (t) => e({
|
|
19
20
|
selectedConnectionId: t,
|
|
21
|
+
folderId: null,
|
|
20
22
|
...r
|
|
21
23
|
}),
|
|
22
24
|
selectFolder: (t) => e({
|
|
23
25
|
folder: t,
|
|
26
|
+
folderId: null,
|
|
27
|
+
...r
|
|
28
|
+
}),
|
|
29
|
+
selectLabel: (t) => e({
|
|
30
|
+
folderId: t,
|
|
24
31
|
...r
|
|
25
32
|
}),
|
|
26
33
|
search: (t) => e({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mailboxStore.js","names":[],"sources":["../../../src/integrations/store/mailboxStore.ts"],"sourcesContent":["/**\n * Mailbox navigation state for the Inbox page (BOFF-4422): which connected\n * mailbox, folder, search and page are shown, which conversation is open, and\n * whether a draft is being written. Package-local; never shared across MFEs.\n */\nimport { create } from 'zustand';\n\nimport { MailboxFolder } from '../../generated/wspace-types';\n\ninterface MailboxState {\n selectedConnectionId: string | null;\n folder: MailboxFolder;\n query: string;\n /** Page tokens visited so far; the last entry is the page on screen. */\n pageTokens: Array<string | null>;\n threadId: string | null;\n composing: boolean;\n sentNotice: boolean;\n\n selectConnection: (connectionId: string) => void;\n selectFolder: (folder: MailboxFolder) => void;\n search: (query: string) => void;\n nextPage: (token: string) => void;\n previousPage: () => void;\n openThread: (threadId: string) => void;\n closeThread: () => void;\n startCompose: () => void;\n closeCompose: () => void;\n composeSent: () => void;\n reset: () => void;\n}\n\nconst initialState = {\n selectedConnectionId: null,\n folder: MailboxFolder.Inbox,\n query: '',\n pageTokens: [null],\n threadId: null,\n composing: false,\n sentNotice: false,\n} satisfies Partial<MailboxState>;\n\n/** Changing what the list shows starts again at its first page. */\nconst freshList = { pageTokens: [null], threadId: null, sentNotice: false };\n\nexport const useMailboxStore = create<MailboxState>((set) => ({\n ...initialState,\n\n selectConnection: (selectedConnectionId)
|
|
1
|
+
{"version":3,"file":"mailboxStore.js","names":[],"sources":["../../../src/integrations/store/mailboxStore.ts"],"sourcesContent":["/**\n * Mailbox navigation state for the Inbox page (BOFF-4422): which connected\n * mailbox, folder, search and page are shown, which conversation is open, and\n * whether a draft is being written. Package-local; never shared across MFEs.\n */\nimport { create } from 'zustand';\n\nimport { MailboxFolder } from '../../generated/wspace-types';\n\ninterface MailboxState {\n selectedConnectionId: string | null;\n folder: MailboxFolder;\n /** A Gmail label or Outlook folder chosen from the label menu; replaces `folder`. */\n folderId: string | null;\n query: string;\n /** Page tokens visited so far; the last entry is the page on screen. */\n pageTokens: Array<string | null>;\n threadId: string | null;\n composing: boolean;\n sentNotice: boolean;\n\n selectConnection: (connectionId: string) => void;\n selectFolder: (folder: MailboxFolder) => void;\n selectLabel: (folderId: string) => void;\n search: (query: string) => void;\n nextPage: (token: string) => void;\n previousPage: () => void;\n openThread: (threadId: string) => void;\n closeThread: () => void;\n startCompose: () => void;\n closeCompose: () => void;\n composeSent: () => void;\n reset: () => void;\n}\n\nconst initialState = {\n selectedConnectionId: null,\n folder: MailboxFolder.Inbox,\n folderId: null,\n query: '',\n pageTokens: [null],\n threadId: null,\n composing: false,\n sentNotice: false,\n} satisfies Partial<MailboxState>;\n\n/** Changing what the list shows starts again at its first page. */\nconst freshList = { pageTokens: [null], threadId: null, sentNotice: false };\n\nexport const useMailboxStore = create<MailboxState>((set) => ({\n ...initialState,\n\n // Labels and folders belong to one mailbox, so switching mailbox drops the choice.\n selectConnection: (selectedConnectionId) =>\n set({ selectedConnectionId, folderId: null, ...freshList }),\n selectFolder: (folder) => set({ folder, folderId: null, ...freshList }),\n selectLabel: (folderId) => set({ folderId, ...freshList }),\n search: (query) => set({ query: query.trim(), ...freshList }),\n nextPage: (token) => set((state) => ({ pageTokens: [...state.pageTokens, token] })),\n previousPage: () =>\n set((state) => ({\n pageTokens: state.pageTokens.length > 1 ? state.pageTokens.slice(0, -1) : state.pageTokens,\n })),\n openThread: (threadId) => set({ threadId, composing: false }),\n closeThread: () => set({ threadId: null }),\n startCompose: () => set({ composing: true, threadId: null, sentNotice: false }),\n closeCompose: () => set({ composing: false }),\n composeSent: () => set({ composing: false, sentNotice: true }),\n reset: () => set(initialState),\n}));\n"],"mappings":";;;AAmCA,IAAM,IAAe;CACnB,sBAAsB;CACtB,QAAQ,EAAc;CACtB,UAAU;CACV,OAAO;CACP,YAAY,CAAC,KAAK;CAClB,UAAU;CACV,WAAW;CACX,YAAY;CACb,EAGK,IAAY;CAAE,YAAY,CAAC,KAAK;CAAE,UAAU;CAAM,YAAY;CAAO,EAE9D,IAAkB,GAAsB,OAAS;CAC5D,GAAG;CAGH,mBAAmB,MACjB,EAAI;EAAE;EAAsB,UAAU;EAAM,GAAG;EAAW,CAAC;CAC7D,eAAe,MAAW,EAAI;EAAE;EAAQ,UAAU;EAAM,GAAG;EAAW,CAAC;CACvE,cAAc,MAAa,EAAI;EAAE;EAAU,GAAG;EAAW,CAAC;CAC1D,SAAS,MAAU,EAAI;EAAE,OAAO,EAAM,MAAM;EAAE,GAAG;EAAW,CAAC;CAC7D,WAAW,MAAU,GAAK,OAAW,EAAE,YAAY,CAAC,GAAG,EAAM,YAAY,EAAM,EAAE,EAAE;CACnF,oBACE,GAAK,OAAW,EACd,YAAY,EAAM,WAAW,SAAS,IAAI,EAAM,WAAW,MAAM,GAAG,GAAG,GAAG,EAAM,YACjF,EAAE;CACL,aAAa,MAAa,EAAI;EAAE;EAAU,WAAW;EAAO,CAAC;CAC7D,mBAAmB,EAAI,EAAE,UAAU,MAAM,CAAC;CAC1C,oBAAoB,EAAI;EAAE,WAAW;EAAM,UAAU;EAAM,YAAY;EAAO,CAAC;CAC/E,oBAAoB,EAAI,EAAE,WAAW,IAAO,CAAC;CAC7C,mBAAmB,EAAI;EAAE,WAAW;EAAO,YAAY;EAAM,CAAC;CAC9D,aAAa,EAAI,EAAa;CAC/B,EAAE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WindowLike } from 'dompurify';
|
|
2
|
+
|
|
3
|
+
export interface MailHtmlOptions {
|
|
4
|
+
/** Load http(s) images. Off by default: remote images track when mail is read. */
|
|
5
|
+
allowRemoteImages: boolean;
|
|
6
|
+
/** Content-ID (without angle brackets) → data: URL of an inline attachment. */
|
|
7
|
+
inlineImages?: ReadonlyMap<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface SanitizedMail {
|
|
10
|
+
/** Body markup, safe to place inside the sandboxed frame. */
|
|
11
|
+
html: string;
|
|
12
|
+
/** Remote images that were (or would have been) blocked. */
|
|
13
|
+
remoteImageCount: number;
|
|
14
|
+
/** cid: images that have no loaded inline attachment yet. */
|
|
15
|
+
unresolvedInlineImages: string[];
|
|
16
|
+
}
|
|
17
|
+
export type MailHtmlSanitizer = (dirty: string, options: MailHtmlOptions) => SanitizedMail;
|
|
18
|
+
/** Builds a sanitiser bound to `win`; without a usable DOM it escapes its input. */
|
|
19
|
+
export declare function createMailHtmlSanitizer(win?: WindowLike): MailHtmlSanitizer;
|
|
20
|
+
/**
|
|
21
|
+
* The Content-Security-Policy of the frame: nothing may load or run, except
|
|
22
|
+
* inline styles, data: images and, when the reader allows them, remote images.
|
|
23
|
+
*/
|
|
24
|
+
export declare function mailFrameCsp(allowRemoteImages: boolean): string;
|
|
25
|
+
/** The complete document the sandboxed frame renders. */
|
|
26
|
+
export declare function mailFrameDocument(bodyHtml: string, allowRemoteImages: boolean): string;
|
|
27
|
+
/** Sanitises mail HTML with a sanitiser bound to the page's window. */
|
|
28
|
+
export declare function sanitizeMailHtml(dirty: string, options: MailHtmlOptions): SanitizedMail;
|
|
29
|
+
/** Human-readable byte size: 512 B, 3.4 KB, 12.0 MB. */
|
|
30
|
+
export declare function formatBytes(bytes: number): string;
|
|
31
|
+
/** Decodes base64 file content into a Blob of the given type. */
|
|
32
|
+
export declare function base64ToBlob(base64: string, mimeType: string): Blob;
|
|
33
|
+
//# sourceMappingURL=mailHtml.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailHtml.d.ts","sourceRoot":"","sources":["../../../src/integrations/utils/mailHtml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAkB,EAAe,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAmDpE,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,iBAAiB,EAAE,OAAO,CAAC;IAC3B,+EAA+E;IAC/E,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,aAAa;IAC5B,6DAA6D;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB,6DAA6D;IAC7D,sBAAsB,EAAE,MAAM,EAAE,CAAC;CAClC;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,KAAK,aAAa,CAAC;AAe3F,oFAAoF;AACpF,wBAAgB,uBAAuB,CAAC,GAAG,CAAC,EAAE,UAAU,GAAG,iBAAiB,CAkD3E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,iBAAiB,EAAE,OAAO,GAAG,MAAM,CAU/D;AAED,yDAAyD;AACzD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAG,MAAM,CAWtF;AAID,uEAAuE;AACvE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,aAAa,CAGvF;AAED,wDAAwD;AACxD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUjD;AAED,iEAAiE;AACjE,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAKnE"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { purify_default as e } from "../../node_modules/dompurify/dist/purify.es.js";
|
|
2
|
+
//#region src/integrations/utils/mailHtml.ts
|
|
3
|
+
var t = [
|
|
4
|
+
"script",
|
|
5
|
+
"link",
|
|
6
|
+
"meta",
|
|
7
|
+
"base",
|
|
8
|
+
"noscript",
|
|
9
|
+
"template",
|
|
10
|
+
"iframe",
|
|
11
|
+
"frame",
|
|
12
|
+
"frameset",
|
|
13
|
+
"object",
|
|
14
|
+
"embed",
|
|
15
|
+
"applet",
|
|
16
|
+
"form",
|
|
17
|
+
"input",
|
|
18
|
+
"button",
|
|
19
|
+
"select",
|
|
20
|
+
"textarea",
|
|
21
|
+
"option",
|
|
22
|
+
"dialog",
|
|
23
|
+
"audio",
|
|
24
|
+
"video",
|
|
25
|
+
"source",
|
|
26
|
+
"track",
|
|
27
|
+
"portal"
|
|
28
|
+
], n = [
|
|
29
|
+
"srcset",
|
|
30
|
+
"action",
|
|
31
|
+
"formaction",
|
|
32
|
+
"ping",
|
|
33
|
+
"background",
|
|
34
|
+
"poster"
|
|
35
|
+
], r = /^(?:(?:https?|mailto|cid):|#)/i, i = /^data:image\/(?:png|gif|jpe?g|webp|avif|bmp);base64,[a-z0-9+/]+=*$/i, a = {
|
|
36
|
+
USE_PROFILES: { html: !0 },
|
|
37
|
+
FORBID_TAGS: t,
|
|
38
|
+
FORBID_ATTR: n,
|
|
39
|
+
ADD_TAGS: ["style"],
|
|
40
|
+
ALLOW_DATA_ATTR: !1,
|
|
41
|
+
ALLOW_UNKNOWN_PROTOCOLS: !1,
|
|
42
|
+
ALLOWED_URI_REGEXP: r,
|
|
43
|
+
SANITIZE_DOM: !0,
|
|
44
|
+
WHOLE_DOCUMENT: !1,
|
|
45
|
+
FORCE_BODY: !0
|
|
46
|
+
};
|
|
47
|
+
function o(e) {
|
|
48
|
+
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
49
|
+
}
|
|
50
|
+
function s(e) {
|
|
51
|
+
return decodeURIComponent(e.trim().slice(4)).replace(/^<|>$/g, "");
|
|
52
|
+
}
|
|
53
|
+
function c(t) {
|
|
54
|
+
let n = t ? e(t) : null;
|
|
55
|
+
return n?.isSupported ? (e, t) => {
|
|
56
|
+
let r = 0, o = /* @__PURE__ */ new Set();
|
|
57
|
+
n.removeAllHooks(), n.addHook("afterSanitizeAttributes", (e) => {
|
|
58
|
+
let n = e.getAttribute("src");
|
|
59
|
+
if (n !== null) {
|
|
60
|
+
let a = n.trim();
|
|
61
|
+
if (e.nodeName !== "IMG") e.removeAttribute("src");
|
|
62
|
+
else if (/^cid:/i.test(a)) {
|
|
63
|
+
let n = s(a), r = t.inlineImages?.get(n);
|
|
64
|
+
r && i.test(r) ? e.setAttribute("src", r) : (o.add(n), e.removeAttribute("src"));
|
|
65
|
+
} else /^https?:/i.test(a) ? (r += 1, t.allowRemoteImages || e.removeAttribute("src")) : /^data:/i.test(a) && !i.test(a) && e.removeAttribute("src");
|
|
66
|
+
}
|
|
67
|
+
if (e.nodeName === "A") {
|
|
68
|
+
let t = e.getAttribute("href");
|
|
69
|
+
t !== null && /^(?:https?|mailto):/i.test(t) ? (e.setAttribute("target", "_blank"), e.setAttribute("rel", "noopener noreferrer")) : (e.removeAttribute("target"), t !== null && !t.startsWith("#") && e.removeAttribute("href"));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
let c = n.sanitize(e, a);
|
|
73
|
+
return n.removeAllHooks(), {
|
|
74
|
+
html: c,
|
|
75
|
+
remoteImageCount: r,
|
|
76
|
+
unresolvedInlineImages: [...o]
|
|
77
|
+
};
|
|
78
|
+
} : (e) => ({
|
|
79
|
+
html: `<pre>${o(e)}</pre>`,
|
|
80
|
+
remoteImageCount: 0,
|
|
81
|
+
unresolvedInlineImages: []
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function l(e) {
|
|
85
|
+
return [
|
|
86
|
+
"default-src 'none'",
|
|
87
|
+
"style-src 'unsafe-inline'",
|
|
88
|
+
e ? "img-src data: https: http:" : "img-src data:",
|
|
89
|
+
"font-src data:",
|
|
90
|
+
"base-uri 'none'",
|
|
91
|
+
"form-action 'none'"
|
|
92
|
+
].join("; ");
|
|
93
|
+
}
|
|
94
|
+
function u(e, t) {
|
|
95
|
+
return [
|
|
96
|
+
"<!doctype html><html><head><meta charset=\"utf-8\">",
|
|
97
|
+
`<meta http-equiv="Content-Security-Policy" content="${l(t)}">`,
|
|
98
|
+
"<meta name=\"referrer\" content=\"no-referrer\">",
|
|
99
|
+
"<style>:root{color-scheme:light}body{margin:0;padding:8px;font-family:system-ui,sans-serif;font-size:14px;overflow-wrap:anywhere}img{max-width:100%;height:auto}</style>",
|
|
100
|
+
"</head><body>",
|
|
101
|
+
e,
|
|
102
|
+
"</body></html>"
|
|
103
|
+
].join("");
|
|
104
|
+
}
|
|
105
|
+
var d = null;
|
|
106
|
+
function f(e, t) {
|
|
107
|
+
return d ??= c(typeof window > "u" ? void 0 : window), d(e, t);
|
|
108
|
+
}
|
|
109
|
+
function p(e) {
|
|
110
|
+
if (!Number.isFinite(e) || e < 1024) return `${Math.max(0, Math.round(e || 0))} B`;
|
|
111
|
+
let t = [
|
|
112
|
+
"KB",
|
|
113
|
+
"MB",
|
|
114
|
+
"GB"
|
|
115
|
+
], n = e / 1024, r = 0;
|
|
116
|
+
for (; n >= 1024 && r < t.length - 1;) n /= 1024, r += 1;
|
|
117
|
+
return `${n.toFixed(1)} ${t[r]}`;
|
|
118
|
+
}
|
|
119
|
+
function m(e, t) {
|
|
120
|
+
let n = atob(e), r = new Uint8Array(n.length);
|
|
121
|
+
for (let e = 0; e < n.length; e += 1) r[e] = n.charCodeAt(e);
|
|
122
|
+
return new Blob([r], { type: t || "application/octet-stream" });
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { m as base64ToBlob, p as formatBytes, u as mailFrameDocument, f as sanitizeMailHtml };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=mailHtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailHtml.js","names":[],"sources":["../../../src/integrations/utils/mailHtml.ts"],"sourcesContent":["/**\n * Rendering untrusted HTML mail (BOFF-10808).\n *\n * The connected mailbox returns a message's HTML body exactly as the provider\n * stores it. Before it is shown it passes three independent layers:\n *\n * 1. A private DOMPurify instance removes scripts, event handlers, frames,\n * forms, embeds, `<base>`, `<meta>` and `<link>`, and every URL scheme\n * except http(s), mailto, cid and raster `data:` images.\n * 2. Remote images are stripped unless the reader chose to load them, and\n * `cid:` references are swapped for the inline attachments the reader\n * already fetched (or dropped when there is none).\n * 3. The result is rendered as `srcdoc` of an iframe sandboxed without\n * `allow-scripts` and carrying a Content-Security-Policy that allows no\n * network fetches at all, except images when the reader allowed them.\n *\n * Without a DOM (tests, server rendering) the sanitiser fails closed.\n */\nimport DOMPurify, { type Config, type WindowLike } from 'dompurify';\n\nconst FORBIDDEN_TAGS = [\n 'script',\n 'link',\n 'meta',\n 'base',\n 'noscript',\n 'template',\n 'iframe',\n 'frame',\n 'frameset',\n 'object',\n 'embed',\n 'applet',\n 'form',\n 'input',\n 'button',\n 'select',\n 'textarea',\n 'option',\n 'dialog',\n 'audio',\n 'video',\n 'source',\n 'track',\n 'portal',\n];\n\nconst FORBIDDEN_ATTRIBUTES = ['srcset', 'action', 'formaction', 'ping', 'background', 'poster'];\n\n/** http(s), mailto, cid (resolved or removed in the hook) and same-document fragments. */\nconst ALLOWED_URI = /^(?:(?:https?|mailto|cid):|#)/i;\n\nconst SAFE_DATA_IMAGE = /^data:image\\/(?:png|gif|jpe?g|webp|avif|bmp);base64,[a-z0-9+/]+=*$/i;\n\nconst MAIL_HTML_CONFIG: Config = {\n USE_PROFILES: { html: true },\n FORBID_TAGS: FORBIDDEN_TAGS,\n FORBID_ATTR: FORBIDDEN_ATTRIBUTES,\n // Mail layout depends on inline styles and <style> blocks; CSS cannot run\n // script here, and the frame's CSP stops any url() it names from loading.\n ADD_TAGS: ['style'],\n ALLOW_DATA_ATTR: false,\n ALLOW_UNKNOWN_PROTOCOLS: false,\n ALLOWED_URI_REGEXP: ALLOWED_URI,\n SANITIZE_DOM: true,\n WHOLE_DOCUMENT: false,\n FORCE_BODY: true,\n};\n\nexport interface MailHtmlOptions {\n /** Load http(s) images. Off by default: remote images track when mail is read. */\n allowRemoteImages: boolean;\n /** Content-ID (without angle brackets) → data: URL of an inline attachment. */\n inlineImages?: ReadonlyMap<string, string>;\n}\n\nexport interface SanitizedMail {\n /** Body markup, safe to place inside the sandboxed frame. */\n html: string;\n /** Remote images that were (or would have been) blocked. */\n remoteImageCount: number;\n /** cid: images that have no loaded inline attachment yet. */\n unresolvedInlineImages: string[];\n}\n\nexport type MailHtmlSanitizer = (dirty: string, options: MailHtmlOptions) => SanitizedMail;\n\nfunction escapeHtml(input: string): string {\n return input\n .replaceAll('&', '&')\n .replaceAll('<', '<')\n .replaceAll('>', '>')\n .replaceAll('\"', '"')\n .replaceAll(\"'\", ''');\n}\n\nfunction cidOf(src: string): string {\n return decodeURIComponent(src.trim().slice(4)).replace(/^<|>$/g, '');\n}\n\n/** Builds a sanitiser bound to `win`; without a usable DOM it escapes its input. */\nexport function createMailHtmlSanitizer(win?: WindowLike): MailHtmlSanitizer {\n const purify = win ? DOMPurify(win) : null;\n if (!purify?.isSupported) {\n return (dirty) => ({\n html: `<pre>${escapeHtml(dirty)}</pre>`,\n remoteImageCount: 0,\n unresolvedInlineImages: [],\n });\n }\n return (dirty, options) => {\n let remoteImageCount = 0;\n const unresolved = new Set<string>();\n purify.removeAllHooks();\n purify.addHook('afterSanitizeAttributes', (element: Element) => {\n const src = element.getAttribute('src');\n if (src !== null) {\n const value = src.trim();\n if (element.nodeName !== 'IMG') {\n element.removeAttribute('src');\n } else if (/^cid:/i.test(value)) {\n const cid = cidOf(value);\n const resolved = options.inlineImages?.get(cid);\n if (resolved && SAFE_DATA_IMAGE.test(resolved)) {\n element.setAttribute('src', resolved);\n } else {\n unresolved.add(cid);\n element.removeAttribute('src');\n }\n } else if (/^https?:/i.test(value)) {\n remoteImageCount += 1;\n if (!options.allowRemoteImages) element.removeAttribute('src');\n } else if (/^data:/i.test(value) && !SAFE_DATA_IMAGE.test(value)) {\n element.removeAttribute('src');\n }\n }\n if (element.nodeName === 'A') {\n const href = element.getAttribute('href');\n if (href !== null && /^(?:https?|mailto):/i.test(href)) {\n element.setAttribute('target', '_blank');\n element.setAttribute('rel', 'noopener noreferrer');\n } else {\n element.removeAttribute('target');\n if (href !== null && !href.startsWith('#')) element.removeAttribute('href');\n }\n }\n });\n const html = purify.sanitize(dirty, MAIL_HTML_CONFIG);\n purify.removeAllHooks();\n return { html, remoteImageCount, unresolvedInlineImages: [...unresolved] };\n };\n}\n\n/**\n * The Content-Security-Policy of the frame: nothing may load or run, except\n * inline styles, data: images and, when the reader allows them, remote images.\n */\nexport function mailFrameCsp(allowRemoteImages: boolean): string {\n const images = allowRemoteImages ? 'img-src data: https: http:' : 'img-src data:';\n return [\n \"default-src 'none'\",\n \"style-src 'unsafe-inline'\",\n images,\n 'font-src data:',\n \"base-uri 'none'\",\n \"form-action 'none'\",\n ].join('; ');\n}\n\n/** The complete document the sandboxed frame renders. */\nexport function mailFrameDocument(bodyHtml: string, allowRemoteImages: boolean): string {\n return [\n '<!doctype html><html><head><meta charset=\"utf-8\">',\n `<meta http-equiv=\"Content-Security-Policy\" content=\"${mailFrameCsp(allowRemoteImages)}\">`,\n '<meta name=\"referrer\" content=\"no-referrer\">',\n // Mail is authored for a light page; keep it legible whatever the app theme.\n '<style>:root{color-scheme:light}body{margin:0;padding:8px;font-family:system-ui,sans-serif;font-size:14px;overflow-wrap:anywhere}img{max-width:100%;height:auto}</style>',\n '</head><body>',\n bodyHtml,\n '</body></html>',\n ].join('');\n}\n\nlet browserSanitizer: MailHtmlSanitizer | null = null;\n\n/** Sanitises mail HTML with a sanitiser bound to the page's window. */\nexport function sanitizeMailHtml(dirty: string, options: MailHtmlOptions): SanitizedMail {\n browserSanitizer ??= createMailHtmlSanitizer(typeof window === 'undefined' ? undefined : window);\n return browserSanitizer(dirty, options);\n}\n\n/** Human-readable byte size: 512 B, 3.4 KB, 12.0 MB. */\nexport function formatBytes(bytes: number): string {\n if (!Number.isFinite(bytes) || bytes < 1024) return `${Math.max(0, Math.round(bytes || 0))} B`;\n const units = ['KB', 'MB', 'GB'];\n let value = bytes / 1024;\n let unit = 0;\n while (value >= 1024 && unit < units.length - 1) {\n value /= 1024;\n unit += 1;\n }\n return `${value.toFixed(1)} ${units[unit]}`;\n}\n\n/** Decodes base64 file content into a Blob of the given type. */\nexport function base64ToBlob(base64: string, mimeType: string): Blob {\n const binary = atob(base64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);\n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