@aglyn/plugins-email 1.0.0-beta.143
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/LICENSE +201 -0
- package/README.md +7 -0
- package/package.json +58 -0
- package/src/index.d.ts +35 -0
- package/src/index.js +35 -0
- package/src/index.js.map +1 -0
- package/src/lib/components/campaign-design-create-widget.d.ts +21 -0
- package/src/lib/components/campaign-design-create-widget.js +61 -0
- package/src/lib/components/campaign-design-create-widget.js.map +1 -0
- package/src/lib/components/campaign-sender-editor-widget.d.ts +18 -0
- package/src/lib/components/campaign-sender-editor-widget.js +39 -0
- package/src/lib/components/campaign-sender-editor-widget.js.map +1 -0
- package/src/lib/components/campaign-topic-options-widget.d.ts +19 -0
- package/src/lib/components/campaign-topic-options-widget.js +48 -0
- package/src/lib/components/campaign-topic-options-widget.js.map +1 -0
- package/src/lib/components/campaign-topic-select.d.ts +32 -0
- package/src/lib/components/campaign-topic-select.js +87 -0
- package/src/lib/components/campaign-topic-select.js.map +1 -0
- package/src/lib/components/dynamic-list-rule-fields.d.ts +173 -0
- package/src/lib/components/dynamic-list-rule-fields.js +1473 -0
- package/src/lib/components/dynamic-list-rule-fields.js.map +1 -0
- package/src/lib/components/email-blocks.d.ts +111 -0
- package/src/lib/components/email-blocks.js +875 -0
- package/src/lib/components/email-blocks.js.map +1 -0
- package/src/lib/components/email-design-preview.d.ts +62 -0
- package/src/lib/components/email-design-preview.js +174 -0
- package/src/lib/components/email-design-preview.js.map +1 -0
- package/src/lib/components/email-screens-card.d.ts +42 -0
- package/src/lib/components/email-screens-card.js +277 -0
- package/src/lib/components/email-screens-card.js.map +1 -0
- package/src/lib/components/email-template-detail.d.ts +48 -0
- package/src/lib/components/email-template-detail.js +681 -0
- package/src/lib/components/email-template-detail.js.map +1 -0
- package/src/lib/components/email-topic-detail.d.ts +32 -0
- package/src/lib/components/email-topic-detail.js +293 -0
- package/src/lib/components/email-topic-detail.js.map +1 -0
- package/src/lib/components/email-topics-card.d.ts +46 -0
- package/src/lib/components/email-topics-card.js +327 -0
- package/src/lib/components/email-topics-card.js.map +1 -0
- package/src/lib/components/email-zones.d.ts +28 -0
- package/src/lib/components/email-zones.js +20 -0
- package/src/lib/components/email-zones.js.map +1 -0
- package/src/lib/components/emails-console-page.d.ts +32 -0
- package/src/lib/components/emails-console-page.js +229 -0
- package/src/lib/components/emails-console-page.js.map +1 -0
- package/src/lib/components/emails-console-sections.d.ts +36 -0
- package/src/lib/components/emails-console-sections.js +108 -0
- package/src/lib/components/emails-console-sections.js.map +1 -0
- package/src/lib/components/list-detail-card.d.ts +47 -0
- package/src/lib/components/list-detail-card.js +273 -0
- package/src/lib/components/list-detail-card.js.map +1 -0
- package/src/lib/components/list-edit-card.d.ts +11 -0
- package/src/lib/components/list-edit-card.js +287 -0
- package/src/lib/components/list-edit-card.js.map +1 -0
- package/src/lib/components/list-import-drawer.d.ts +22 -0
- package/src/lib/components/list-import-drawer.js +662 -0
- package/src/lib/components/list-import-drawer.js.map +1 -0
- package/src/lib/components/list-members-panel.d.ts +94 -0
- package/src/lib/components/list-members-panel.js +686 -0
- package/src/lib/components/list-members-panel.js.map +1 -0
- package/src/lib/components/lists-card.d.ts +28 -0
- package/src/lib/components/lists-card.js +377 -0
- package/src/lib/components/lists-card.js.map +1 -0
- package/src/lib/components/sending-domain-detail.d.ts +26 -0
- package/src/lib/components/sending-domain-detail.js +496 -0
- package/src/lib/components/sending-domain-detail.js.map +1 -0
- package/src/lib/components/sending-domains-card.d.ts +33 -0
- package/src/lib/components/sending-domains-card.js +962 -0
- package/src/lib/components/sending-domains-card.js.map +1 -0
- package/src/lib/components/sending-sender-drawer.d.ts +94 -0
- package/src/lib/components/sending-sender-drawer.js +543 -0
- package/src/lib/components/sending-sender-drawer.js.map +1 -0
- package/src/lib/components/suppressions-card.d.ts +49 -0
- package/src/lib/components/suppressions-card.js +639 -0
- package/src/lib/components/suppressions-card.js.map +1 -0
- package/src/lib/components/use-org-email-topics.d.ts +79 -0
- package/src/lib/components/use-org-email-topics.js +111 -0
- package/src/lib/components/use-org-email-topics.js.map +1 -0
- package/src/lib/constants/bundle-common.d.ts +18 -0
- package/src/lib/constants/bundle-common.js +18 -0
- package/src/lib/constants/bundle-common.js.map +1 -0
- package/src/lib/hooks/use-org-company-options.d.ts +20 -0
- package/src/lib/hooks/use-org-company-options.js +138 -0
- package/src/lib/hooks/use-org-company-options.js.map +1 -0
- package/src/lib/hooks/use-org-contact-fields.d.ts +40 -0
- package/src/lib/hooks/use-org-contact-fields.js +91 -0
- package/src/lib/hooks/use-org-contact-fields.js.map +1 -0
- package/src/lib/hooks/use-org-contact-segments.d.ts +16 -0
- package/src/lib/hooks/use-org-contact-segments.js +55 -0
- package/src/lib/hooks/use-org-contact-segments.js.map +1 -0
- package/src/lib/hooks/use-org-crm-views.d.ts +8 -0
- package/src/lib/hooks/use-org-crm-views.js +74 -0
- package/src/lib/hooks/use-org-crm-views.js.map +1 -0
- package/src/lib/hooks/use-org-lists.d.ts +8 -0
- package/src/lib/hooks/use-org-lists.js +47 -0
- package/src/lib/hooks/use-org-lists.js.map +1 -0
- package/src/lib/model/email-design-document.d.ts +52 -0
- package/src/lib/model/email-design-document.js +62 -0
- package/src/lib/model/email-design-document.js.map +1 -0
- package/src/lib/model/index.d.ts +64 -0
- package/src/lib/model/index.js +71 -0
- package/src/lib/model/index.js.map +1 -0
- package/src/lib/model/sending-domain-status.d.ts +99 -0
- package/src/lib/model/sending-domain-status.js +196 -0
- package/src/lib/model/sending-domain-status.js.map +1 -0
- package/src/lib/model/template-provenance.d.ts +113 -0
- package/src/lib/model/template-provenance.js +107 -0
- package/src/lib/model/template-provenance.js.map +1 -0
- package/src/lib/model/template-report.d.ts +158 -0
- package/src/lib/model/template-report.js +249 -0
- package/src/lib/model/template-report.js.map +1 -0
- package/src/lib/plugin.d.ts +27 -0
- package/src/lib/plugin.js +163 -0
- package/src/lib/plugin.js.map +1 -0
- package/src/lib/server-console.d.ts +116 -0
- package/src/lib/server-console.js +422 -0
- package/src/lib/server-console.js.map +1 -0
- package/src/lib/server-email-drafts.d.ts +104 -0
- package/src/lib/server-email-drafts.js +381 -0
- package/src/lib/server-email-drafts.js.map +1 -0
- package/src/lib/server-list-gate.d.ts +183 -0
- package/src/lib/server-list-gate.js +365 -0
- package/src/lib/server-list-gate.js.map +1 -0
- package/src/lib/server-list-import.d.ts +199 -0
- package/src/lib/server-list-import.js +632 -0
- package/src/lib/server-list-import.js.map +1 -0
- package/src/lib/server-suppressions.d.ts +135 -0
- package/src/lib/server-suppressions.js +295 -0
- package/src/lib/server-suppressions.js.map +1 -0
- package/src/lib/server.d.ts +19 -0
- package/src/lib/server.js +834 -0
- package/src/lib/server.js.map +1 -0
- package/src/lib/site.d.ts +26 -0
- package/src/lib/site.js +81 -0
- package/src/lib/site.js.map +1 -0
- package/src/lib/unsubscribe-link.d.ts +311 -0
- package/src/lib/unsubscribe-link.js +398 -0
- package/src/lib/unsubscribe-link.js.map +1 -0
- package/src/lib/utils/create-email-screen.d.ts +59 -0
- package/src/lib/utils/create-email-screen.js +59 -0
- package/src/lib/utils/create-email-screen.js.map +1 -0
- package/src/lib/utils/generate-preset-id.d.ts +19 -0
- package/src/lib/utils/generate-preset-id.js +25 -0
- package/src/lib/utils/generate-preset-id.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/email/src/lib/components/suppressions-card.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport { ICON_VARIANT_CLOSE } from '@aglyn/shared-data-enums'\nimport { mdiEmailCheckOutline } from '@aglyn/shared-data-mdi'\nimport {\n CardDisplay,\n Container,\n MdiIcon,\n SrOnly,\n useConfirmationContext,\n} from '@aglyn/shared-ui-jsx'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport {\n ListRowActions,\n ListTable,\n listActionsColumn,\n} from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport { TABLE_ROW_HEIGHT } from '@aglyn/shared-ui-jsx/const/table-pagination'\n/*\n * The shared drawer, reached by its own path.\n *\n * `@aglyn/shared-ui-jsx`'s barrel deliberately does not re-export this one, so\n * a deep import is the supported way in rather than an escape hatch. The\n * console's `CreateArtifactDrawer` — what Screens, Components, Layouts and\n * Templates create through — is this same component with a form inside it,\n * and it lives in `apps/console`, which a plugin library may not import. So\n * the chrome is composed from the same primitive rather than duplicated from\n * the wrapper.\n */\nimport { NavigationDrawerComponent } from '@aglyn/shared-ui-jsx/components/navigation-drawer.component'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n Chip,\n IconButton,\n Stack,\n TextField,\n Typography,\n} from '@mui/material'\nimport Button from '@mui/material/Button'\nimport type { GridColDef } from '@mui/x-data-grid'\nimport {\n collection,\n count,\n deleteDoc,\n doc,\n getAggregateFromServer,\n limit,\n orderBy,\n query,\n where,\n} from 'firebase/firestore'\nimport { useCallback, useEffect, useState } from 'react'\nimport {\n useFirestore,\n usePagedCollection,\n useUser,\n} from '@aglyn/tenant-feature-instance'\nimport { authorizedFetch } from '@aglyn/shared-util-http/authorized-token'\n\nexport interface SuppressionsCardProps {\n hostId: string\n}\n\n/** A stored entry. `reason` is absent on anything written before AGL-2408. */\ninterface SuppressionRow {\n $id: string\n email?: string\n reason?: string\n suppressedAt?: { seconds?: number } | null\n createdAt?: { seconds?: number } | null\n}\n\n/**\n * What a reason means to a merchant, and how much it should worry them.\n *\n * An ABSENT reason reads as \"Unsubscribed\", and that is a compatibility rule\n * rather than a guess: until AGL-2408 the unsubscribe handler wrote\n * `{ email, createdAt }` and nothing else, while the Resend webhook has\n * stamped `'bounce'`/`'complaint'` since AGL-1918 — so an entry with no reason\n * can only have come from somebody clicking the link. New unsubscribes write\n * the reason explicitly, so this fallback covers history and nothing else.\n */\nconst REASONS: Record<string, { label: string; color: 'default' | 'warning' | 'error' }> = {\n unsubscribe: { label: 'Unsubscribed', color: 'default' },\n bounce: { label: 'Bounced', color: 'warning' },\n complaint: { label: 'Marked as spam', color: 'error' },\n /*\n * Recorded by a person, through the Add control.\n *\n * Its OWN value rather than a reuse of `unsubscribe`: an opt-out arriving\n * by reply, phone or in person is not somebody clicking a link, and the\n * difference is exactly what a merchant asked to prove the request was\n * honored has to be able to show.\n */\n manual: { label: 'Added by hand', color: 'default' },\n}\n\nconst describeReason = (reason: unknown) =>\n REASONS[String(reason ?? 'unsubscribe')] ?? {\n label: String(reason),\n color: 'default' as const,\n }\n\n/**\n * `YYYY-MM-DD` from a Firestore timestamp shape, or an em dash.\n *\n * `createdAt` first, and that ordering is the column's meaning rather than a\n * preference. Both writers restamp `suppressedAt` on every touch and write\n * `createdAt` only when the document is new, precisely so that a bounce\n * arriving after an unsubscribe does not move the date the person actually\n * unsubscribed. Reading `suppressedAt` first put the restamp on screen under a\n * heading that says \"Since\", and it is also the field the list is ordered by,\n * so a re-touched row would have sorted by one date and displayed another.\n */\nfunction onDate(row: SuppressionRow): string {\n const seconds = row.createdAt?.seconds ?? row.suppressedAt?.seconds\n if (!seconds) return '—'\n return new Date(seconds * 1000).toISOString().slice(0, 10)\n}\n\n/**\n * Suppressions (AGL-2410): who is not being emailed, and why.\n *\n * ## What was missing\n *\n * `hosts/{hostId}/suppressions` was written by two paths — the unsubscribe\n * handler and, since AGL-1918, the Resend webhook on a permanent bounce or a\n * complaint — and read by exactly one: `campaign-send.ts`, to filter an\n * audience. Nothing in the console displayed it. So a merchant could not\n * answer any of:\n *\n * - *\"My campaign says 500 recipients and 480 sent — who were the other\n * 20?\"* The send returns `{recipients, sent}` and the difference was\n * unexplained.\n * - *\"Is my list going stale?\"* A bounce rate is the single most useful\n * number about a list and there was nowhere to see it.\n * - *\"This address was suppressed by mistake.\"* There was no way to remove\n * an entry — and a link prescanner unsubscribing someone (AGL-2408 §2) was\n * therefore unrecoverable from inside the product.\n *\n * ## Why a surface and not another counter\n *\n * AGL-1918 deliberately did NOT write a `stats.bounces` counter alongside its\n * fix, because a number with no screen to show it is the written-but-never-\n * read shape this issue is about, one level up. So the fix is the READER, and\n * the breakdown here is derived from the rows on screen rather than from a\n * second stored figure that could disagree with them.\n *\n * ## Removing an entry\n *\n * A plain client `deleteDoc`, and that is a decision. The list belongs to the\n * merchant, host admins already read it through the same rules, and removing\n * a row does nothing except make an address targetable again — there is no\n * counter to launder and no money attached, which is the AGL-1367 test for\n * whether a write has to move server-side.\n *\n * The confirmation is not decoration either: for a `bounce` the address very\n * likely does not exist, and mailing it again is what a provider scores the\n * sending domain on. So the dialog says which reason is being overridden\n * rather than asking a generic \"are you sure\".\n */\nexport function SuppressionsCard(props: SuppressionsCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const { confirm } = useConfirmationContext()\n const [adding, setAdding] = useState(false)\n\n const [addInput, setAddInput] = useState('')\n const [addNote, setAddNote] = useState('')\n const [busy, setBusy] = useState(false)\n\n /*\n * The window IS the query, ordered by the server (AGL-2501, AGL-2292).\n *\n * This was `limit(500)` with no `orderBy`, sorted by date in the browser.\n * Firestore answers an unordered limit in DOCUMENT-ID order, and an entry\n * here is keyed by `sha256(email)` — so the window was five hundred\n * addresses chosen by the hash of the address, and the client sort dressed\n * that sample up as the newest five hundred. A list past the ceiling\n * therefore hid whoever bounced this morning behind whoever happened to\n * hash low, with no gap on screen to notice and no control asking for more.\n *\n * `createdAt` is the safe field to order on, and that is checked rather\n * than assumed: both writers — the unsubscribe handler and the Resend\n * bounce/complaint webhook — stamp it when the document is created, the\n * pre-AGL-2408 handler wrote `{ email, createdAt }`, and `suppressions` is\n * not in `IMPORTABLE_FIELDS`, so no restore path can produce a row without\n * one. `suppressedAt` would NOT be safe: it is absent on every entry\n * written before AGL-1918, and `orderBy` drops documents that lack the\n * field rather than mis-sorting them.\n */\n const {\n rows: entries,\n hasMore,\n page,\n setPage,\n pageSize,\n setPageSize,\n } = usePagedCollection<SuppressionRow>(\n (pageLimit) =>\n query(\n collection(firestore, 'hosts', hostId, 'suppressions'),\n orderBy('createdAt', 'desc'),\n limit(pageLimit),\n ),\n [firestore, hostId],\n { idField: '$id' },\n )\n\n /*==========================================\n * THE BREAKDOWN IS A SERVER AGGREGATE, not a tally of the page.\n *\n * These chips answer \"is my list going stale?\", and they were a `reduce`\n * over whatever the listener had fetched — so on a site past the old\n * ceiling \"Bounced: 140\" meant 140 of an arbitrary five hundred, and under\n * a ten-row page it would have meant 140 of ten. A bounce rate computed\n * from a sample is not a bounce rate, and nothing on screen said it was one.\n *\n * Three reads, not one per reason. `where('reason','==','unsubscribe')`\n * cannot be asked, because an entry written before AGL-2408 carries no\n * `reason` at all and an equality filter excludes it — the same\n * field-presence trap as the ordering above. Unsubscribes are therefore the\n * REMAINDER: total minus the two reasons that are always written\n * explicitly, which is exactly the compatibility rule `describeReason`\n * applies row by row.\n *=========================================*/\n const [totalsEpoch, setTotalsEpoch] = useState(0)\n const [totals, setTotals] = useState<Record<string, number> | null>(null)\n useEffect(() => {\n let active = true\n const suppressionsRef = collection(firestore, 'hosts', hostId, 'suppressions')\n void Promise.all([\n getAggregateFromServer(suppressionsRef, { total: count() }),\n getAggregateFromServer(\n query(suppressionsRef, where('reason', '==', 'bounce')),\n { total: count() },\n ),\n getAggregateFromServer(\n query(suppressionsRef, where('reason', '==', 'complaint')),\n { total: count() },\n ),\n // A FOURTH read, and it is not optional. Unsubscribes are the\n // REMAINDER, so every reason that is counted explicitly has to be\n // subtracted — a hand-added entry left out of this list would be\n // reported as somebody who clicked unsubscribe.\n getAggregateFromServer(\n query(suppressionsRef, where('reason', '==', 'manual')),\n { total: count() },\n ),\n ])\n .then(([all, bounced, complained, added]) => {\n if (!active) return\n const total = Number(all.data().total ?? 0)\n const bounce = Number(bounced.data().total ?? 0)\n const complaint = Number(complained.data().total ?? 0)\n const manual = Number(added.data().total ?? 0)\n setTotals({\n unsubscribe: Math.max(0, total - bounce - complaint - manual),\n bounce,\n complaint,\n manual,\n })\n })\n .catch(() => {\n // Held at null rather than zeroed. \"Bounced: 0\" is a confident wrong\n // number in the reassuring direction, and this card exists to warn.\n if (active) setTotals(null)\n })\n return () => {\n active = false\n }\n // The list is a live listener and refreshes itself; an aggregate is a\n // one-shot read and would otherwise keep reporting the breakdown from\n // before the address was put back.\n }, [firestore, hostId, totalsEpoch])\n\n /*\n * The ADD, through a route rather than a client write.\n *\n * The Remove button below writes straight from the browser, and this does\n * not, which looks inconsistent until the document id is considered: an\n * entry is keyed by `sha256` of the normalized address, and a browser\n * computing that itself would be a second derivation of the key every\n * reader shares. Getting it wrong is silent and one-directional — the\n * merchant is told the person is suppressed and the mail keeps going. A\n * removal has no such hazard: it names a row that is already on screen.\n */\n const handleAdd = useCallback(async () => {\n const typed = addInput.trim()\n if (!typed || busy) return\n setBusy(true)\n try {\n const response = await authorizedFetch(\n user,\n '/api/email/suppression-add',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, emails: typed, note: addNote.trim() }),\n },\n )\n const payload = await response.json().catch(() => ({}))\n if (!response.ok) {\n return void enqueueSnackbar(\n payload?.error ?? 'The address could not be suppressed.',\n { variant: 'error' },\n )\n }\n const results = (payload?.results ?? []) as Array<{\n input: string\n added: boolean\n refusal?: string\n }>\n const added = Number(payload?.added ?? 0)\n const rejected = results.filter(\n (result) => result.refusal === 'not-an-address',\n )\n // The refusals are NAMED, because \"3 of 5 added\" leaves an operator to\n // work out which two, and the two that failed are the ones somebody\n // asked to stop being emailed.\n if (rejected.length) {\n enqueueSnackbar(\n `Not an email address: ${rejected\n .map((result) => result.input)\n .join(', ')}`,\n { variant: 'warning' },\n )\n }\n if (added) {\n enqueueSnackbar(\n added === 1\n ? 'Added to the suppression list'\n : `${added} addresses added to the suppression list`,\n { variant: 'success', persist: false },\n )\n } else if (!rejected.length) {\n enqueueSnackbar('Already on the suppression list', { variant: 'info' })\n }\n if (added) {\n setAddInput('')\n setAddNote('')\n setAdding(false)\n setTotalsEpoch((epoch) => epoch + 1)\n }\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', { variant: 'error' })\n } finally {\n setBusy(false)\n }\n }, [addInput, addNote, busy, user, hostId, enqueueSnackbar])\n\n /**\n * Whether one address is ALSO on the platform-wide list.\n *\n * The two lists are consulted together at send time and were visible\n * separately, so a merchant who removed their own entry could still find\n * the address was never mailed, with nothing anywhere saying why. The\n * platform entry is invisible to them and cannot be lifted by them, which\n * is precisely why it has to be said before the click rather than\n * discovered from a recipient count that stays short.\n */\n const isBlockedPlatformWide = useCallback(\n async (email: string): Promise<boolean> => {\n try {\n const response = await authorizedFetch(\n user,\n '/api/email/suppression-status',\n {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ hostId, emails: email }),\n },\n )\n if (!response.ok) return false\n const payload = await response.json().catch(() => ({}))\n return ((payload?.platform ?? []) as string[]).length > 0\n } catch (error) {\n console.error(error)\n return false\n }\n },\n [user, hostId],\n )\n\n const handleRemove = async (row: SuppressionRow) => {\n const reason = describeReason(row.reason).label.toLowerCase()\n // The platform entry is invisible to a merchant and cannot be lifted by\n // one, so removing the site's row here changes nothing about whether the\n // address is mailed. Saying so BEFORE the click is the whole point: the\n // alternative is a merchant who removes the row, sends again, and sees a\n // recipient count that is still short with nothing explaining it.\n /*\n * ASKED, NOT MOUNTED.\n *\n * One keyed read for the one address the merchant is acting on, at the\n * moment they act. Fetching this for every visible row on mount would be\n * a request per page render for an answer that is only ever needed on a\n * click, and this card is one tab of a page a merchant opens to read.\n *\n * A failed check answers \"not blocked\", which is the ordinary case: the\n * dialog then reads exactly as it did before, and the removal still\n * works. Refusing to open the dialog because a supplementary lookup\n * failed would make an outage on an explanation into an outage on the\n * control it explains.\n */\n const alsoPlatform = row.email\n ? await isBlockedPlatformWide(row.email)\n : false\n const accepted = await confirm({\n title: alsoPlatform\n ? 'This address will still be skipped'\n : 'Put this address back on your list?',\n description: alsoPlatform\n ? `${row.email ?? 'This address'} bounced permanently or reported ` +\n 'spam somewhere else in Aglyn, so it is on the platform-wide list ' +\n 'as well as yours. Removing your entry will not start mail ' +\n 'reaching it — contact support to have the platform entry lifted.'\n : `${row.email ?? 'This address'} is suppressed because it ` +\n `${reason === 'bounced' ? 'bounced permanently' : reason === 'marked as spam' ? 'was marked as spam' : reason === 'added by hand' ? 'was added by hand' : 'unsubscribed'}. ` +\n 'Removing the entry means your next campaign will email it again.',\n confirmationText: 'Remove',\n confirmationButtonProps: { color: 'error' },\n })\n // `confirm` resolves with NO VALUE and REJECTS on cancel, so gating on\n // the resolved value alone makes this always return (AGL-950).\n .then(() => true)\n .catch(() => false)\n if (!accepted) return\n try {\n await deleteDoc(\n doc(firestore, 'hosts', hostId, 'suppressions', row.$id),\n )\n enqueueSnackbar('Removed from the suppression list', {\n variant: 'success',\n persist: false,\n })\n setTotalsEpoch((epoch) => epoch + 1)\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', { variant: 'error' })\n }\n }\n\n const columns: GridColDef<SuppressionRow>[] = [\n {\n field: 'email',\n headerName: 'Address',\n flex: 1,\n minWidth: 240,\n /*\n Entries are keyed by `sha256(email)` because addresses are PII, and the\n address itself is stored in the document. An older row written before\n the address was stored has only its hash — which tells a merchant\n nothing, so it says so rather than displaying 64 hex characters.\n */\n renderCell: ({ row }) =>\n row.email || (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'(address not recorded)'}\n </Typography>\n ),\n },\n {\n field: 'reason',\n headerName: 'Reason',\n width: 170,\n valueGetter: (_value, row) => describeReason(row.reason).label,\n renderCell: ({ row }) => {\n const described = describeReason(row.reason)\n return (\n <Chip\n size=\"small\"\n color={described.color}\n variant=\"outlined\"\n label={described.label}\n />\n )\n },\n },\n {\n field: 'since',\n headerName: 'Since',\n width: 140,\n valueGetter: (_value, row) => onDate(row),\n },\n /*\n A SUPPRESSION HAS NO PAGE, so the row does not open one — this is the\n surface's one list whose rows are not a way in to anything. What it does\n have is the one act a merchant performs on an entry, and the trailing\n cluster is where every other list on this surface keeps that: a bare\n `Remove` in the row is a click that puts an address back into mailing\n range, sitting where the reader's eye is running along the row.\n */\n listActionsColumn(\n (row: SuppressionRow) => (\n <ListRowActions\n label={row.email || 'this entry'}\n items={[\n {\n key: 'remove',\n label: 'Remove from the list',\n icon: <MdiIcon path={mdiEmailCheckOutline.path} size={0.8} />,\n destructive: true,\n onClick: () => void handleRemove(row),\n },\n ]}\n />\n ),\n { width: 72 },\n ),\n ]\n\n return (\n <CardDisplay\n header=\"Suppressions\"\n help={pluginDocsHelp('emailCampaigns', { anchor: '#compliance' })}\n contentGutterX\n contentGutterY\n contentBordered=\"all\"\n HeaderProps={{\n action: (\n <Button\n size=\"small\"\n variant=\"contained\"\n onClick={() => setAdding(true)}\n >\n {'Add'}\n </Button>\n ),\n }}\n >\n <Stack spacing={1.5}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Addresses this site’s marketing email skips. Someone lands here ' +\n 'by clicking unsubscribe, by bouncing permanently, by marking a ' +\n 'message as spam, or because you added them — this is where the ' +\n 'gap between a campaign’s recipient count and what it actually ' +\n 'sent comes from.'}\n </Typography>\n {entries.length === 0 ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Nobody is suppressed. Every address in your audiences is ' +\n 'currently mailable.'}\n </Typography>\n ) : (\n <>\n <Stack direction=\"row\" spacing={1} sx={{ flexWrap: 'wrap' }}>\n {totals === null ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Could not read the breakdown. This is not the same as ' +\n 'nobody having bounced.'}\n </Typography>\n ) : (\n Object.entries(totals)\n // A reason nobody has hit is not news, and three chips\n // reading zero make the two that matter harder to find.\n .filter(([, total]) => total > 0)\n .map(([reason, total]) => {\n const described = describeReason(reason)\n return (\n <Chip\n key={reason}\n size=\"small\"\n color={described.color}\n variant=\"outlined\"\n label={`${described.label}: ${total}`}\n />\n )\n })\n )}\n </Stack>\n <ListTable\n aria-label=\"Suppressed addresses\"\n rows={entries}\n columns={columns}\n rowHeight={TABLE_ROW_HEIGHT}\n // Paged by the footer below, so the grid must not also slice.\n hideFooter\n />\n <ListPagination\n page={page}\n pageSize={pageSize}\n rowCount={entries.length}\n hasMore={hasMore}\n // The collection's real size, so the footer's count line says\n // \"1–10 of 812\" rather than \"of more than 10\" — the aggregate\n // above already knows it, and it is the same number the chips\n // are a breakdown of.\n count={totals ? Object.values(totals).reduce((a, b) => a + b, 0) : undefined}\n onPageChange={setPage}\n onPageSizeChange={setPageSize}\n />\n </>\n )}\n </Stack>\n {/*\n A DRAWER, not a form stacked above the table.\n Creating is a drawer and picking is a dialog, which is how Screens,\n Components, Layouts and Templates all take a name before they create\n one; the chrome here is the same `NavigationDrawerComponent` those go\n through, composed directly because the console's wrapper around it\n lives in an application a plugin library may not import.\n */}\n <NavigationDrawerComponent\n open={adding}\n anchor=\"right\"\n variant=\"temporary\"\n onClose={() => setAdding(false)}\n AppBarProps={{ color: 'surface' }}\n appBarLeft={\n <>\n <IconButton\n color=\"inherit\"\n edge=\"start\"\n onClick={() => setAdding(false)}\n sx={{ mr: 2 }}\n >\n <MdiIcon path={ICON_VARIANT_CLOSE.path} />\n <SrOnly>{'close drawer'}</SrOnly>\n </IconButton>\n <Typography variant=\"h6\" component=\"div\">\n {'Stop emailing an address'}\n </Typography>\n </>\n }\n appBarRight={\n <Button\n variant=\"outlined\"\n color=\"inherit\"\n onClick={() => setAdding(false)}\n >\n {'Cancel'}\n </Button>\n }\n >\n <Container gutterY>\n <Stack spacing={2}>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {'Use this when somebody asks you to stop emailing them by ' +\n 'reply, by phone, or in person. They stay on your audiences ' +\n 'and keep every record you hold about them — this only stops ' +\n 'this site’s marketing email reaching them.'}\n </Typography>\n <TextField\n label=\"Email addresses\"\n value={addInput}\n onChange={(event) => setAddInput(event.target.value)}\n multiline\n minRows={3}\n fullWidth\n autoFocus\n helperText={\n 'One per line, or separated by commas. Up to 50 at a time.'\n }\n />\n <TextField\n label=\"Note (optional)\"\n value={addNote}\n onChange={(event) => setAddNote(event.target.value)}\n fullWidth\n helperText={\n 'How the request reached you. Kept with the entry as the ' +\n 'record that it was honored.'\n }\n slotProps={{ htmlInput: { maxLength: 200 } }}\n />\n <Alert severity=\"info\">\n {'Order confirmations, booking reminders and password resets ' +\n 'are unaffected. Somebody who asked to stop hearing from ' +\n 'your marketing still gets their receipt.'}\n </Alert>\n <Stack direction=\"row\" spacing={1} sx={{ justifyContent: 'flex-end' }}>\n <Button\n variant=\"contained\"\n disabled={busy || !addInput.trim()}\n onClick={() => void handleAdd()}\n >\n {'Add to suppression list'}\n </Button>\n </Stack>\n </Stack>\n </Container>\n </NavigationDrawerComponent>\n </CardDisplay>\n )\n}\nSuppressionsCard.displayName = 'SuppressionsCard'\n\nexport default SuppressionsCard\n"],"names":["pluginDocsHelp","ICON_VARIANT_CLOSE","mdiEmailCheckOutline","CardDisplay","Container","MdiIcon","SrOnly","useConfirmationContext","ListPagination","ListRowActions","ListTable","listActionsColumn","TABLE_ROW_HEIGHT","NavigationDrawerComponent","useSnackbar","Alert","Chip","IconButton","Stack","TextField","Typography","Button","collection","count","deleteDoc","doc","getAggregateFromServer","limit","orderBy","query","where","useCallback","useEffect","useState","useFirestore","usePagedCollection","useUser","authorizedFetch","REASONS","unsubscribe","label","color","bounce","complaint","manual","describeReason","reason","String","onDate","row","seconds","createdAt","suppressedAt","Date","toISOString","slice","SuppressionsCard","props","hostId","firestore","data","user","enqueueSnackbar","confirm","adding","setAdding","addInput","setAddInput","addNote","setAddNote","busy","setBusy","rows","entries","hasMore","page","setPage","pageSize","setPageSize","pageLimit","idField","totalsEpoch","setTotalsEpoch","totals","setTotals","active","suppressionsRef","Promise","all","total","then","bounced","complained","added","Number","Math","max","catch","handleAdd","typed","trim","response","method","headers","body","JSON","stringify","emails","note","payload","json","ok","error","variant","results","rejected","filter","result","refusal","length","map","input","join","persist","epoch","console","isBlockedPlatformWide","email","platform","handleRemove","toLowerCase","alsoPlatform","accepted","title","description","confirmationText","confirmationButtonProps","$id","columns","field","headerName","flex","minWidth","renderCell","width","valueGetter","_value","described","size","items","key","icon","path","destructive","onClick","header","help","anchor","contentGutterX","contentGutterY","contentBordered","HeaderProps","action","spacing","direction","sx","flexWrap","Object","aria-label","rowHeight","hideFooter","rowCount","values","reduce","a","b","undefined","onPageChange","onPageSizeChange","open","onClose","AppBarProps","appBarLeft","edge","mr","component","appBarRight","gutterY","value","onChange","event","target","multiline","minRows","fullWidth","autoFocus","helperText","slotProps","htmlInput","maxLength","severity","justifyContent","disabled","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SAASA,cAAc,QAAQ,eAAc;AAC7C,SAASC,kBAAkB,QAAQ,2BAA0B;AAC7D,SAASC,oBAAoB,QAAQ,yBAAwB;AAC7D,SACEC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,sBAAsB,QACjB,uBAAsB;AAC7B,SAASC,cAAc,QAAQ,4DAA2D;AAC1F,SACEC,cAAc,EACdC,SAAS,EACTC,iBAAiB,QACZ,uDAAsD;AAC7D,SAASC,gBAAgB,QAAQ,8CAA6C;AAC9E;;;;;;;;;;CAUC,GACD,SAASC,yBAAyB,QAAQ,8DAA6D;AACvG,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,IAAI,EACJC,UAAU,EACVC,KAAK,EACLC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,OAAOC,YAAY,uBAAsB;AAEzC,SACE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;AAQjB;AACA1C,iBAAiBmJ,WAAW,GAAG;AAE/B,eAAenJ,iBAAgB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type EmailTopic } from '@aglyn/aglyn';
|
|
2
|
+
import type { Firestore } from 'firebase/firestore';
|
|
3
|
+
/**
|
|
4
|
+
* Write one topic's document — the ONE writer of the topic catalog.
|
|
5
|
+
*
|
|
6
|
+
* Two surfaces change a topic: its own page, which edits the name and the
|
|
7
|
+
* description, and the list card's row menu, which retires and restores. They
|
|
8
|
+
* write the same document and have to agree about its shape, so the write
|
|
9
|
+
* lives here rather than once in each.
|
|
10
|
+
*
|
|
11
|
+
* ## Why it is a complete statement and not a patch
|
|
12
|
+
*
|
|
13
|
+
* `archived` is written on every save rather than only when it changes. A
|
|
14
|
+
* merge that omitted it would leave a restored topic carrying `archived: true`
|
|
15
|
+
* from an earlier save — which reads on screen as restored and behaves as
|
|
16
|
+
* retired, because the composer's picker and the recipient's preference page
|
|
17
|
+
* both read the stored flag.
|
|
18
|
+
*
|
|
19
|
+
* ## Why a built-in saves the same way
|
|
20
|
+
*
|
|
21
|
+
* `DEFAULT_EMAIL_TOPICS` is the FLOOR of the catalog, not its initial
|
|
22
|
+
* contents: the four built-ins have no stored document until somebody changes
|
|
23
|
+
* one. `setDoc` at the built-in's own id is what creates the override, so the
|
|
24
|
+
* same call serves a custom topic and a built-in being retired for the first
|
|
25
|
+
* time.
|
|
26
|
+
*/
|
|
27
|
+
export declare function writeEmailTopic(firestore: Firestore, scope: readonly [string, string], topic: {
|
|
28
|
+
id: string;
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
archived: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether this stream needs a confirmation click, or `null`/omitted for
|
|
34
|
+
* "whatever the site says".
|
|
35
|
+
*
|
|
36
|
+
* The only field on this document with THREE states, which is why it is
|
|
37
|
+
* the only one written conditionally: `archived` is written on every save
|
|
38
|
+
* because a merge that omitted it would carry an old value forward, and a
|
|
39
|
+
* `doubleOptIn` written on every save could never be un-chosen back to
|
|
40
|
+
* the site default. `deleteField()` is what returns it, so clearing is a
|
|
41
|
+
* real act rather than a value that happens to look like an absence.
|
|
42
|
+
*/
|
|
43
|
+
doubleOptIn?: boolean | null;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* The org's email topic catalog, as both the console card and the composer's
|
|
47
|
+
* picker read it.
|
|
48
|
+
*
|
|
49
|
+
* ONE hook for both surfaces, because they have to agree: a topic the composer
|
|
50
|
+
* offers must be one the preference page can render, and a topic the card
|
|
51
|
+
* archives must leave the picker. Two reads of the same collection with two
|
|
52
|
+
* different merge rules is how the composer comes to send a campaign under a
|
|
53
|
+
* topic nobody can unsubscribe from.
|
|
54
|
+
*
|
|
55
|
+
* ORG-scoped, following `lists` (AGL-254) — see `email-topics.ts` for why the
|
|
56
|
+
* definitions are org-shared while the recipient's opt-outs are per site.
|
|
57
|
+
*
|
|
58
|
+
* Ordered by the server rather than capped and re-sorted here (AGL-2501,
|
|
59
|
+
* AGL-2292). `name` is safe to order on because every writer of this
|
|
60
|
+
* collection is the topics card, which refuses to save a nameless topic —
|
|
61
|
+
* `orderBy` DROPS documents that lack the field rather than mis-sorting them,
|
|
62
|
+
* so that claim is about the writers and not a preference.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useOrgEmailTopics(hostId: string, options?: {
|
|
65
|
+
/**
|
|
66
|
+
* Whether to read at all. Default true.
|
|
67
|
+
*
|
|
68
|
+
* For a caller whose only use of the catalog is a picker inside a control
|
|
69
|
+
* somebody has to open — a create drawer, an edit drawer — where reading
|
|
70
|
+
* on mount charges every reader of the list for a field none of them
|
|
71
|
+
* asked for. A `false` here opens no listener, exactly as a null query
|
|
72
|
+
* does, and the catalog reads as empty until it flips.
|
|
73
|
+
*/
|
|
74
|
+
enabled?: boolean;
|
|
75
|
+
}): {
|
|
76
|
+
topics: EmailTopic[];
|
|
77
|
+
/** `['orgs', orgId]`, or null until the org lookup settles. */
|
|
78
|
+
scope: readonly [string, string] | null;
|
|
79
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ 'use client';
|
|
17
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
|
+
import { EMAIL_TOPICS_COLLECTION, mergeEmailTopics, normalizeEmailTopic } from "@aglyn/aglyn";
|
|
19
|
+
import { collection, deleteField, doc, limit, orderBy, query, setDoc } from "firebase/firestore";
|
|
20
|
+
import { useMemo } from "react";
|
|
21
|
+
import { useFirestore, useFirestoreCollection, useOrgDataScope } from "@aglyn/tenant-feature-instance";
|
|
22
|
+
/**
|
|
23
|
+
* Write one topic's document — the ONE writer of the topic catalog.
|
|
24
|
+
*
|
|
25
|
+
* Two surfaces change a topic: its own page, which edits the name and the
|
|
26
|
+
* description, and the list card's row menu, which retires and restores. They
|
|
27
|
+
* write the same document and have to agree about its shape, so the write
|
|
28
|
+
* lives here rather than once in each.
|
|
29
|
+
*
|
|
30
|
+
* ## Why it is a complete statement and not a patch
|
|
31
|
+
*
|
|
32
|
+
* `archived` is written on every save rather than only when it changes. A
|
|
33
|
+
* merge that omitted it would leave a restored topic carrying `archived: true`
|
|
34
|
+
* from an earlier save — which reads on screen as restored and behaves as
|
|
35
|
+
* retired, because the composer's picker and the recipient's preference page
|
|
36
|
+
* both read the stored flag.
|
|
37
|
+
*
|
|
38
|
+
* ## Why a built-in saves the same way
|
|
39
|
+
*
|
|
40
|
+
* `DEFAULT_EMAIL_TOPICS` is the FLOOR of the catalog, not its initial
|
|
41
|
+
* contents: the four built-ins have no stored document until somebody changes
|
|
42
|
+
* one. `setDoc` at the built-in's own id is what creates the override, so the
|
|
43
|
+
* same call serves a custom topic and a built-in being retired for the first
|
|
44
|
+
* time.
|
|
45
|
+
*/ export async function writeEmailTopic(firestore, scope, topic) {
|
|
46
|
+
await setDoc(doc(firestore, scope[0], scope[1], EMAIL_TOPICS_COLLECTION, topic.id), _extends({
|
|
47
|
+
name: topic.name,
|
|
48
|
+
description: topic.description,
|
|
49
|
+
archived: topic.archived
|
|
50
|
+
}, topic.doubleOptIn === undefined ? {} : {
|
|
51
|
+
doubleOptIn: topic.doubleOptIn === null ? deleteField() : topic.doubleOptIn
|
|
52
|
+
}), {
|
|
53
|
+
merge: true
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* How many stored topics one read fetches.
|
|
58
|
+
*
|
|
59
|
+
* A ceiling on the READ, not on the catalog. A preference page stops being a
|
|
60
|
+
* preference page somewhere well before two hundred checkboxes, so an org that
|
|
61
|
+
* reaches this has a different problem than a truncated list — and the read is
|
|
62
|
+
* ordered, so what a merchant past it loses is the tail of the alphabet rather
|
|
63
|
+
* than an arbitrary sample.
|
|
64
|
+
*/ const TOPIC_READ_CEILING = 200;
|
|
65
|
+
/**
|
|
66
|
+
* The org's email topic catalog, as both the console card and the composer's
|
|
67
|
+
* picker read it.
|
|
68
|
+
*
|
|
69
|
+
* ONE hook for both surfaces, because they have to agree: a topic the composer
|
|
70
|
+
* offers must be one the preference page can render, and a topic the card
|
|
71
|
+
* archives must leave the picker. Two reads of the same collection with two
|
|
72
|
+
* different merge rules is how the composer comes to send a campaign under a
|
|
73
|
+
* topic nobody can unsubscribe from.
|
|
74
|
+
*
|
|
75
|
+
* ORG-scoped, following `lists` (AGL-254) — see `email-topics.ts` for why the
|
|
76
|
+
* definitions are org-shared while the recipient's opt-outs are per site.
|
|
77
|
+
*
|
|
78
|
+
* Ordered by the server rather than capped and re-sorted here (AGL-2501,
|
|
79
|
+
* AGL-2292). `name` is safe to order on because every writer of this
|
|
80
|
+
* collection is the topics card, which refuses to save a nameless topic —
|
|
81
|
+
* `orderBy` DROPS documents that lack the field rather than mis-sorting them,
|
|
82
|
+
* so that claim is about the writers and not a preference.
|
|
83
|
+
*/ export function useOrgEmailTopics(hostId, options) {
|
|
84
|
+
var _ref;
|
|
85
|
+
const firestore = useFirestore();
|
|
86
|
+
const enabled = (_ref = options == null ? void 0 : options.enabled) != null ? _ref : true;
|
|
87
|
+
// The org lookup is async (AGL-1061): null until it settles, and null
|
|
88
|
+
// forever for a host with no owning org.
|
|
89
|
+
const { scope } = useOrgDataScope({
|
|
90
|
+
hostId
|
|
91
|
+
});
|
|
92
|
+
const { data: stored } = useFirestoreCollection(()=>scope && enabled ? query(collection(firestore, scope[0], scope[1], EMAIL_TOPICS_COLLECTION), orderBy('name'), limit(TOPIC_READ_CEILING)) : null, [
|
|
93
|
+
firestore,
|
|
94
|
+
scope,
|
|
95
|
+
enabled
|
|
96
|
+
], {
|
|
97
|
+
idField: '$id'
|
|
98
|
+
});
|
|
99
|
+
const topics = useMemo(()=>mergeEmailTopics((stored != null ? stored : []).map((doc)=>{
|
|
100
|
+
var _doc_$id;
|
|
101
|
+
return normalizeEmailTopic(String((_doc_$id = doc['$id']) != null ? _doc_$id : ''), doc);
|
|
102
|
+
}).filter((topic)=>!!topic)), [
|
|
103
|
+
stored
|
|
104
|
+
]);
|
|
105
|
+
return {
|
|
106
|
+
topics,
|
|
107
|
+
scope: scope
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=use-org-email-topics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/email/src/lib/components/use-org-email-topics.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n EMAIL_TOPICS_COLLECTION,\n mergeEmailTopics,\n normalizeEmailTopic,\n type EmailTopic,\n} from '@aglyn/aglyn'\nimport type { Firestore } from 'firebase/firestore'\nimport {\n collection,\n deleteField,\n doc,\n limit,\n orderBy,\n query,\n setDoc,\n} from 'firebase/firestore'\nimport { useMemo } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useOrgDataScope,\n} from '@aglyn/tenant-feature-instance'\n\n/**\n * Write one topic's document — the ONE writer of the topic catalog.\n *\n * Two surfaces change a topic: its own page, which edits the name and the\n * description, and the list card's row menu, which retires and restores. They\n * write the same document and have to agree about its shape, so the write\n * lives here rather than once in each.\n *\n * ## Why it is a complete statement and not a patch\n *\n * `archived` is written on every save rather than only when it changes. A\n * merge that omitted it would leave a restored topic carrying `archived: true`\n * from an earlier save — which reads on screen as restored and behaves as\n * retired, because the composer's picker and the recipient's preference page\n * both read the stored flag.\n *\n * ## Why a built-in saves the same way\n *\n * `DEFAULT_EMAIL_TOPICS` is the FLOOR of the catalog, not its initial\n * contents: the four built-ins have no stored document until somebody changes\n * one. `setDoc` at the built-in's own id is what creates the override, so the\n * same call serves a custom topic and a built-in being retired for the first\n * time.\n */\nexport async function writeEmailTopic(\n firestore: Firestore,\n scope: readonly [string, string],\n topic: {\n id: string\n name: string\n description: string\n archived: boolean\n /**\n * Whether this stream needs a confirmation click, or `null`/omitted for\n * \"whatever the site says\".\n *\n * The only field on this document with THREE states, which is why it is\n * the only one written conditionally: `archived` is written on every save\n * because a merge that omitted it would carry an old value forward, and a\n * `doubleOptIn` written on every save could never be un-chosen back to\n * the site default. `deleteField()` is what returns it, so clearing is a\n * real act rather than a value that happens to look like an absence.\n */\n doubleOptIn?: boolean | null\n },\n): Promise<void> {\n await setDoc(\n doc(firestore, scope[0], scope[1], EMAIL_TOPICS_COLLECTION, topic.id),\n {\n name: topic.name,\n description: topic.description,\n archived: topic.archived,\n ...(topic.doubleOptIn === undefined\n ? {}\n : {\n doubleOptIn:\n topic.doubleOptIn === null ? deleteField() : topic.doubleOptIn,\n }),\n },\n { merge: true },\n )\n}\n\n/**\n * How many stored topics one read fetches.\n *\n * A ceiling on the READ, not on the catalog. A preference page stops being a\n * preference page somewhere well before two hundred checkboxes, so an org that\n * reaches this has a different problem than a truncated list — and the read is\n * ordered, so what a merchant past it loses is the tail of the alphabet rather\n * than an arbitrary sample.\n */\nconst TOPIC_READ_CEILING = 200\n\n/**\n * The org's email topic catalog, as both the console card and the composer's\n * picker read it.\n *\n * ONE hook for both surfaces, because they have to agree: a topic the composer\n * offers must be one the preference page can render, and a topic the card\n * archives must leave the picker. Two reads of the same collection with two\n * different merge rules is how the composer comes to send a campaign under a\n * topic nobody can unsubscribe from.\n *\n * ORG-scoped, following `lists` (AGL-254) — see `email-topics.ts` for why the\n * definitions are org-shared while the recipient's opt-outs are per site.\n *\n * Ordered by the server rather than capped and re-sorted here (AGL-2501,\n * AGL-2292). `name` is safe to order on because every writer of this\n * collection is the topics card, which refuses to save a nameless topic —\n * `orderBy` DROPS documents that lack the field rather than mis-sorting them,\n * so that claim is about the writers and not a preference.\n */\nexport function useOrgEmailTopics(\n hostId: string,\n options?: {\n /**\n * Whether to read at all. Default true.\n *\n * For a caller whose only use of the catalog is a picker inside a control\n * somebody has to open — a create drawer, an edit drawer — where reading\n * on mount charges every reader of the list for a field none of them\n * asked for. A `false` here opens no listener, exactly as a null query\n * does, and the catalog reads as empty until it flips.\n */\n enabled?: boolean\n },\n): {\n topics: EmailTopic[]\n /** `['orgs', orgId]`, or null until the org lookup settles. */\n scope: readonly [string, string] | null\n} {\n const firestore = useFirestore()\n const enabled = options?.enabled ?? true\n // The org lookup is async (AGL-1061): null until it settles, and null\n // forever for a host with no owning org.\n const { scope } = useOrgDataScope({ hostId })\n const { data: stored } = useFirestoreCollection<Record<string, unknown>>(\n () =>\n scope && enabled\n ? query(\n collection(firestore, scope[0], scope[1], EMAIL_TOPICS_COLLECTION),\n orderBy('name'),\n limit(TOPIC_READ_CEILING),\n )\n : null,\n [firestore, scope, enabled],\n { idField: '$id' },\n )\n const topics = useMemo(\n () =>\n mergeEmailTopics(\n (stored ?? [])\n .map((doc) => normalizeEmailTopic(String(doc['$id'] ?? ''), doc))\n .filter((topic): topic is EmailTopic => !!topic),\n ),\n [stored],\n )\n return { topics, scope: scope as readonly [string, string] | null }\n}\n"],"names":["EMAIL_TOPICS_COLLECTION","mergeEmailTopics","normalizeEmailTopic","collection","deleteField","doc","limit","orderBy","query","setDoc","useMemo","useFirestore","useFirestoreCollection","useOrgDataScope","writeEmailTopic","firestore","scope","topic","id","name","description","archived","doubleOptIn","undefined","merge","TOPIC_READ_CEILING","useOrgEmailTopics","hostId","options","enabled","data","stored","idField","topics","map","String","filter"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA,SACEA,uBAAuB,EACvBC,gBAAgB,EAChBC,mBAAmB,QAEd,eAAc;AAErB,SACEC,UAAU,EACVC,WAAW,EACXC,GAAG,EACHC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,MAAM,QACD,qBAAoB;AAC3B,SAASC,OAAO,QAAQ,QAAO;AAC/B,SACEC,YAAY,EACZC,sBAAsB,EACtBC,eAAe,QACV,iCAAgC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,eAAeC,gBACpBC,SAAoB,EACpBC,KAAgC,EAChCC,KAiBC;IAED,M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right 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/** Persisted as pluginId in email screen docs (AGL-346). */
|
|
18
|
+
export declare const BUNDLE_ID = "email";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ /** Persisted as pluginId in email screen docs (AGL-346). */ export const BUNDLE_ID = 'email';
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=bundle-common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/email/src/lib/constants/bundle-common.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** Persisted as pluginId in email screen docs (AGL-346). */\nexport const BUNDLE_ID = 'email'\n"],"names":["BUNDLE_ID"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GAED,0DAA0D,GAC1D,OAAO,MAAMA,YAAY,QAAO"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** One company, as much of it as a picker needs. */
|
|
2
|
+
export interface OrgCompanyOption {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
/** How many hits one typed prefix returns. */
|
|
7
|
+
export declare const COMPANY_SEARCH_LIMIT = 20;
|
|
8
|
+
export declare function useOrgCompanyOptions(options: {
|
|
9
|
+
scope: readonly [string, string];
|
|
10
|
+
/** What the merchant has typed. Empty reads nothing. */
|
|
11
|
+
search: string;
|
|
12
|
+
/** The ids the rule already names, whose names the chips need. */
|
|
13
|
+
selectedIds: readonly string[];
|
|
14
|
+
}): {
|
|
15
|
+
hits: OrgCompanyOption[];
|
|
16
|
+
/** Every name known, by id — hits and resolved selections alike. */
|
|
17
|
+
names: Record<string, string>;
|
|
18
|
+
searching: boolean;
|
|
19
|
+
};
|
|
20
|
+
export default useOrgCompanyOptions;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Aglyn LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/ 'use client';
|
|
17
|
+
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
18
|
+
/**
|
|
19
|
+
* The org's companies, as a SEARCH rather than a list (AGL-2603).
|
|
20
|
+
*
|
|
21
|
+
* A picker over every company an org has is the unbounded read this console
|
|
22
|
+
* refuses, and a company list is exactly the collection that grows past any
|
|
23
|
+
* dropdown. So the control is a search box: what the merchant types becomes
|
|
24
|
+
* a prefix range on `nameLower`, the key `nameSearchFields` writes beside
|
|
25
|
+
* every company name, bounded to one screen of hits. Nothing is read until
|
|
26
|
+
* something is typed.
|
|
27
|
+
*
|
|
28
|
+
* ## The chosen ids keep their names
|
|
29
|
+
*
|
|
30
|
+
* A rule stores company IDS, and a chip reading `co_8f2a…` tells the reader
|
|
31
|
+
* nothing. The hook keeps a name for every id it has ever seen — from a hit,
|
|
32
|
+
* or from a keyed read of a stored id the search never touched — so a rule
|
|
33
|
+
* reopened months later still names the company it filters on. A keyed
|
|
34
|
+
* `getDoc` rather than an `in` query, because an `in` on document ids cannot
|
|
35
|
+
* be combined with the `array-contains-any` a scoped viewer's query needs,
|
|
36
|
+
* and a document read is evaluated by the rules per document either way.
|
|
37
|
+
*
|
|
38
|
+
* ## Scoped like the contacts themselves
|
|
39
|
+
*
|
|
40
|
+
* The same viewer-token narrowing every CRM read applies; an org-wide member
|
|
41
|
+
* searches without a filter.
|
|
42
|
+
*/ import { CRM_COLLECTIONS, nameSearchKey } from "@aglyn/aglyn";
|
|
43
|
+
import { collection, doc, endAt, getDoc, limit, orderBy, query, startAt, where } from "firebase/firestore";
|
|
44
|
+
import { useEffect, useMemo, useState } from "react";
|
|
45
|
+
import { useFirestore, useFirestoreCollection, useScopeTokens } from "@aglyn/tenant-feature-instance";
|
|
46
|
+
/** How many hits one typed prefix returns. */ export const COMPANY_SEARCH_LIMIT = 20;
|
|
47
|
+
/** How many stored ids a reopened rule resolves names for, by keyed read. */ const COMPANY_NAME_RESOLUTION_CAP = 30;
|
|
48
|
+
export function useOrgCompanyOptions(options) {
|
|
49
|
+
const { scope, search, selectedIds } = options;
|
|
50
|
+
const firestore = useFirestore();
|
|
51
|
+
const { tokens, orgWide, loaded } = useScopeTokens(scope[1]);
|
|
52
|
+
const key = nameSearchKey(search);
|
|
53
|
+
const { data, status } = useFirestoreCollection(()=>key && loaded ? query(collection(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies), ...orgWide ? [] : [
|
|
54
|
+
where('visibleTo', 'array-contains-any', tokens)
|
|
55
|
+
], orderBy('nameLower'), startAt(key), endAt(key + ''), limit(COMPANY_SEARCH_LIMIT)) : null, [
|
|
56
|
+
firestore,
|
|
57
|
+
scope[0],
|
|
58
|
+
scope[1],
|
|
59
|
+
key,
|
|
60
|
+
loaded,
|
|
61
|
+
orgWide,
|
|
62
|
+
tokens
|
|
63
|
+
], {
|
|
64
|
+
idField: '$id'
|
|
65
|
+
});
|
|
66
|
+
/*
|
|
67
|
+
* Names accumulate and are never forgotten within the form's life: a hit
|
|
68
|
+
* that scrolls out of the current search is still the company a chip
|
|
69
|
+
* names. Keyed by id, and only ever ADDED to, so a stored id resolved once
|
|
70
|
+
* is not resolved again on every keystroke.
|
|
71
|
+
*/ const [resolved, setResolved] = useState({});
|
|
72
|
+
const hitNames = useMemo(()=>Object.fromEntries((data != null ? data : []).map((row)=>{
|
|
73
|
+
var _row_name;
|
|
74
|
+
return [
|
|
75
|
+
row.$id,
|
|
76
|
+
String((_row_name = row.name) != null ? _row_name : row.$id)
|
|
77
|
+
];
|
|
78
|
+
})), [
|
|
79
|
+
data
|
|
80
|
+
]);
|
|
81
|
+
const unresolved = useMemo(()=>selectedIds.filter((id)=>!(id in resolved) && !(id in hitNames)).slice(0, COMPANY_NAME_RESOLUTION_CAP), [
|
|
82
|
+
selectedIds,
|
|
83
|
+
resolved,
|
|
84
|
+
hitNames
|
|
85
|
+
]);
|
|
86
|
+
useEffect(()=>{
|
|
87
|
+
if (!unresolved.length) return;
|
|
88
|
+
let active = true;
|
|
89
|
+
void Promise.all(unresolved.map(async (id)=>{
|
|
90
|
+
try {
|
|
91
|
+
var _snapshot_get;
|
|
92
|
+
const snapshot = await getDoc(doc(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies, id));
|
|
93
|
+
return [
|
|
94
|
+
id,
|
|
95
|
+
String((_snapshot_get = snapshot.get('name')) != null ? _snapshot_get : id)
|
|
96
|
+
];
|
|
97
|
+
} catch (unused) {
|
|
98
|
+
// A company the viewer may not read, or one that was deleted,
|
|
99
|
+
// keeps its id as its name rather than blocking the others.
|
|
100
|
+
return [
|
|
101
|
+
id,
|
|
102
|
+
id
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
})).then((entries)=>{
|
|
106
|
+
if (active) {
|
|
107
|
+
setResolved((held)=>_extends({}, held, Object.fromEntries(entries)));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
return ()=>{
|
|
111
|
+
active = false;
|
|
112
|
+
};
|
|
113
|
+
}, [
|
|
114
|
+
unresolved,
|
|
115
|
+
firestore,
|
|
116
|
+
scope
|
|
117
|
+
]);
|
|
118
|
+
return useMemo(()=>({
|
|
119
|
+
hits: (data != null ? data : []).map((row)=>{
|
|
120
|
+
var _row_name;
|
|
121
|
+
return {
|
|
122
|
+
id: row.$id,
|
|
123
|
+
label: String((_row_name = row.name) != null ? _row_name : row.$id)
|
|
124
|
+
};
|
|
125
|
+
}),
|
|
126
|
+
names: _extends({}, resolved, hitNames),
|
|
127
|
+
searching: Boolean(key) && status === 'loading'
|
|
128
|
+
}), [
|
|
129
|
+
data,
|
|
130
|
+
resolved,
|
|
131
|
+
hitNames,
|
|
132
|
+
key,
|
|
133
|
+
status
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
export default useOrgCompanyOptions;
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=use-org-company-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/email/src/lib/hooks/use-org-company-options.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\n/**\n * The org's companies, as a SEARCH rather than a list (AGL-2603).\n *\n * A picker over every company an org has is the unbounded read this console\n * refuses, and a company list is exactly the collection that grows past any\n * dropdown. So the control is a search box: what the merchant types becomes\n * a prefix range on `nameLower`, the key `nameSearchFields` writes beside\n * every company name, bounded to one screen of hits. Nothing is read until\n * something is typed.\n *\n * ## The chosen ids keep their names\n *\n * A rule stores company IDS, and a chip reading `co_8f2a…` tells the reader\n * nothing. The hook keeps a name for every id it has ever seen — from a hit,\n * or from a keyed read of a stored id the search never touched — so a rule\n * reopened months later still names the company it filters on. A keyed\n * `getDoc` rather than an `in` query, because an `in` on document ids cannot\n * be combined with the `array-contains-any` a scoped viewer's query needs,\n * and a document read is evaluated by the rules per document either way.\n *\n * ## Scoped like the contacts themselves\n *\n * The same viewer-token narrowing every CRM read applies; an org-wide member\n * searches without a filter.\n */\n\nimport { CRM_COLLECTIONS, nameSearchKey } from '@aglyn/aglyn'\nimport {\n collection,\n doc,\n endAt,\n getDoc,\n limit,\n orderBy,\n query,\n startAt,\n where,\n} from 'firebase/firestore'\nimport { useEffect, useMemo, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreCollection,\n useScopeTokens,\n} from '@aglyn/tenant-feature-instance'\n\n/** One company, as much of it as a picker needs. */\nexport interface OrgCompanyOption {\n id: string\n label: string\n}\n\n/** How many hits one typed prefix returns. */\nexport const COMPANY_SEARCH_LIMIT = 20\n\n/** How many stored ids a reopened rule resolves names for, by keyed read. */\nconst COMPANY_NAME_RESOLUTION_CAP = 30\n\nexport function useOrgCompanyOptions(options: {\n scope: readonly [string, string]\n /** What the merchant has typed. Empty reads nothing. */\n search: string\n /** The ids the rule already names, whose names the chips need. */\n selectedIds: readonly string[]\n}): {\n hits: OrgCompanyOption[]\n /** Every name known, by id — hits and resolved selections alike. */\n names: Record<string, string>\n searching: boolean\n} {\n const { scope, search, selectedIds } = options\n const firestore = useFirestore()\n const { tokens, orgWide, loaded } = useScopeTokens(scope[1])\n const key = nameSearchKey(search)\n\n const { data, status } = useFirestoreCollection<{\n $id: string\n name?: string\n }>(\n () =>\n key && loaded\n ? query(\n collection(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies),\n ...(orgWide ? [] : [where('visibleTo', 'array-contains-any', tokens)]),\n orderBy('nameLower'),\n startAt(key),\n endAt(key + ''),\n limit(COMPANY_SEARCH_LIMIT),\n )\n : null,\n [firestore, scope[0], scope[1], key, loaded, orgWide, tokens],\n { idField: '$id' },\n )\n\n /*\n * Names accumulate and are never forgotten within the form's life: a hit\n * that scrolls out of the current search is still the company a chip\n * names. Keyed by id, and only ever ADDED to, so a stored id resolved once\n * is not resolved again on every keystroke.\n */\n const [resolved, setResolved] = useState<Record<string, string>>({})\n const hitNames = useMemo(\n () =>\n Object.fromEntries(\n (data ?? []).map((row) => [row.$id, String(row.name ?? row.$id)]),\n ),\n [data],\n )\n const unresolved = useMemo(\n () =>\n selectedIds\n .filter((id) => !(id in resolved) && !(id in hitNames))\n .slice(0, COMPANY_NAME_RESOLUTION_CAP),\n [selectedIds, resolved, hitNames],\n )\n useEffect(() => {\n if (!unresolved.length) return\n let active = true\n void Promise.all(\n unresolved.map(async (id) => {\n try {\n const snapshot = await getDoc(\n doc(firestore, scope[0], scope[1], CRM_COLLECTIONS.companies, id),\n )\n return [id, String(snapshot.get('name') ?? id)] as const\n } catch {\n // A company the viewer may not read, or one that was deleted,\n // keeps its id as its name rather than blocking the others.\n return [id, id] as const\n }\n }),\n ).then((entries) => {\n if (active) {\n setResolved((held) => ({ ...held, ...Object.fromEntries(entries) }))\n }\n })\n return () => {\n active = false\n }\n }, [unresolved, firestore, scope])\n\n return useMemo(\n () => ({\n hits: (data ?? []).map((row) => ({\n id: row.$id,\n label: String(row.name ?? row.$id),\n })),\n names: { ...resolved, ...hitNames },\n searching: Boolean(key) && status === 'loading',\n }),\n [data, resolved, hitNames, key, status],\n )\n}\n\nexport default useOrgCompanyOptions\n"],"names":["CRM_COLLECTIONS","nameSearchKey","collection","doc","endAt","getDoc","limit","orderBy","query","startAt","where","useEffect","useMemo","useState","useFirestore","useFirestoreCollection","useScopeTokens","COMPANY_SEARCH_LIMIT","COMPANY_NAME_RESOLUTION_CAP","useOrgCompanyOptions","options","scope","search","selectedIds","firestore","tokens","orgWide","loaded","key","data","status","companies","idField","resolved","setResolved","hitNames","Object","fromEntries","map","row","$id","String","name","unresolved","filter","id","slice","length","active","Promise","all","snapshot","get","then","entries","held","hits","label","names","searching","Boolean"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GAED,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAc;AAC7D,SACEC,UAAU,EACVC,GAAG,EACHC,KAAK,EACLC,MAAM,EACNC,KAAK,EACLC,OAAO,EACPC,KAAK,EACLC,OAAO,EACPC,KAAK,QACA,qBAAoB;AAC3B,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACpD,SACEC,YAAY,EACZC,sBAAsB,EACtBC,cAAc,QACT,iCAAgC;AAQvC,4CAA4C,GAC5C,OAA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U;QACR,IAAI,CAACgC,WAAWI,MAAM,EAAE;QACxB,IAAIC,SAAS;QACb,KAAKC,QAAQC,GAAG,CACdP,WAAWL,GAAG,CAAC,OAAOO;YACpB,IAAI;oBAIiBM;gBAHnB,MAAMA,WAAW,MAAM9C,OACrBF,IAAIqB,WAAWH,KAAK,CAAC,EAAE,EAAEA,KAAK,CAAC,EAAE,EAAErB,gBAAgB+B,SAAS,EAAEc;gBAEhE,OAAO;oBAACA;oBAAIJ,QAAOU,gBAAAA,SAASC,GAAG,CAAC,mBAAbD,gBAAwBN;iBAAI;YACjD,EAAE,eAAM;gBACN,8DAA8D;gBAC9D,4DAA4D;gBAC5D,OAAO;oBAACA;oBAAIA;iBAAG;YACjB;QACF,IACAQ,IAAI,CAAC,CAACC;YACN,IAAIN,QAAQ;gBACVd,YAAY,CAACqB,OAAU,aAAKA,MAASnB,OAAOC,WAAW,CAACiB;YAC1D;QACF;QACA,OAAO;YACLN,SAAS;QACX;IACF,GAAG;QAACL;QAAYnB;QAAWH;KAAM;IAEjC,OAAOT,QACL,IAAO,CAAA;YACL4C,MAAM,CAAC3B,eAAAA,OAAQ,EAAE,EAAES,GAAG,CAAC,CAACC;oBAERA;uBAFiB;oBAC/BM,IAAIN,IAAIC,GAAG;oBACXiB,OAAOhB,QAAOF,YAAAA,IAAIG,IAAI,YAARH,YAAYA,IAAIC,GAAG;gBACnC;;YACAkB,OAAO,aAAKzB,UAAaE;YACzBwB,WAAWC,QAAQhC,QAAQE,WAAW;QACxC,CAAA,GACA;QAACD;QAAMI;QAAUE;QAAUP;QAAKE;KAAO;AAE3C;AAEA,eAAeX,qBAAoB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The org's custom contact field DEFINITIONS, for the rule editor to offer
|
|
3
|
+
* (AGL-2603).
|
|
4
|
+
*
|
|
5
|
+
* A twin of `use-org-lists.ts`: a LOOKUP that fills one control's options,
|
|
6
|
+
* bounded so an org cannot turn the dropdown into an unbounded read. The
|
|
7
|
+
* definitions live in `orgs/{orgId}/contactFields` and the values a rule
|
|
8
|
+
* compares against live under each contact facet's `custom`, keyed by the
|
|
9
|
+
* definition's `key` — so the picker offers keys, and the clause it authors
|
|
10
|
+
* names one.
|
|
11
|
+
*
|
|
12
|
+
* ## Scoped like the contacts themselves
|
|
13
|
+
*
|
|
14
|
+
* The rules gate the collection on the contacts predicate, per document, so
|
|
15
|
+
* a collaborator scoped to one site reading it unfiltered is refused rather
|
|
16
|
+
* than shown less. The viewer's scope tokens narrow the query the way every
|
|
17
|
+
* CRM read is narrowed; an org-wide member reads without a filter, which is
|
|
18
|
+
* what keeps a definition the backfill never stamped from vanishing for them.
|
|
19
|
+
*
|
|
20
|
+
* ## A retired field is offered nowhere new
|
|
21
|
+
*
|
|
22
|
+
* `retiredAt` is a retirement, not a deletion: values written under the key
|
|
23
|
+
* survive and an export still reads them back. A rule written before the
|
|
24
|
+
* retirement keeps its clause — the editor shows the key it names — but the
|
|
25
|
+
* picker stops offering the field, because a merchant building a new
|
|
26
|
+
* audience on a field their team has retired is building it on a value
|
|
27
|
+
* nobody is maintaining.
|
|
28
|
+
*/
|
|
29
|
+
import { type ContactFieldDefinition } from '@aglyn/aglyn';
|
|
30
|
+
/** One definition, as the picker and the value control need it. */
|
|
31
|
+
export type OrgContactFieldOption = Pick<ContactFieldDefinition, 'key' | 'label' | 'type' | 'options' | 'order'> & {
|
|
32
|
+
$id: string;
|
|
33
|
+
};
|
|
34
|
+
/** The picker's window. Matches the list and segment pickers beside it. */
|
|
35
|
+
export declare const CONTACT_FIELD_PICKER_LIMIT = 50;
|
|
36
|
+
export declare function useOrgContactFields(scope: readonly [string, string]): {
|
|
37
|
+
fields: OrgContactFieldOption[];
|
|
38
|
+
ready: boolean;
|
|
39
|
+
};
|
|
40
|
+
export default useOrgContactFields;
|